473,474 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

upload file issue

First of all I am rather new into PHP. I use php 5 and I am putting
together a web site for a local association I belong too.
Most of the site is okay, except for this problem :

I need to be able for the member of the site to upload files (gif, jpg
or pdf). After reading a lot about the danger of file uploading, I
decided to create a folder at the root of the web server. The upload of
the files goes on without any problem, but when i tried to show some of
the file (such as the image files), the system does not retrieve them.

Here is the the tree of my web server :
/.
/website (folder where all of the web site is build with *.php files)
/uploads
/images (folder where all the images files are uploaded)
/pdf (files where all the pdf files are uploaded)

The bit of code doing the uploads works fine, but I can not find a way
to retrieve the files. When I code in the php file :
echo '<img src="../uploads/images/test.gif">';
The browser is in fact looking for a file name
www.mywebsite.com/uploads/images/test.gif which of course does not exist.

I tried to look on the web for an answer but did not find one. Could any
one points me out to a tutorial for this subject, or will be good enough
to help with a solution, bearing in mind that I am by no mean an expert
in php.

Thank you.
Apr 17 '07 #1
6 2193

"Emmanuel Petit" <em**************@free.frwrote in message
news:46***********************@news.free.fr...
First of all I am rather new into PHP. I use php 5 and I am putting
together a web site for a local association I belong too.
Most of the site is okay, except for this problem :

I need to be able for the member of the site to upload files (gif, jpg or
pdf). After reading a lot about the danger of file uploading, I decided to
create a folder at the root of the web server. The upload of the files
goes on without any problem, but when i tried to show some of the file
(such as the image files), the system does not retrieve them.

Here is the the tree of my web server :
/.
/website (folder where all of the web site is build with *.php files)
/uploads
/images (folder where all the images files are uploaded)
/pdf (files where all the pdf files are uploaded)

The bit of code doing the uploads works fine, but I can not find a way to
retrieve the files. When I code in the php file :
echo '<img src="../uploads/images/test.gif">';
The browser is in fact looking for a file name
www.mywebsite.com/uploads/images/test.gif which of course does not exist.

I tried to look on the web for an answer but did not find one. Could any
one points me out to a tutorial for this subject, or will be good enough
to help with a solution, bearing in mind that I am by no mean an expert in
php.

Thank you.
I am sure that there may be another solution, but I think that you cannot
path back outside of your webserver. I'd bet that if you moved the 'uploads'
folder inside the 'website' folder and change the link accordingly, it would
work.

As www.mywebsite.com and the website folder should be the same ... I take it
that having <img src='../../uploads/images/test.gif'makes no difference?


Apr 17 '07 #2
Sean a écrit :
>
I am sure that there may be another solution, but I think that you cannot
path back outside of your webserver. I'd bet that if you moved the 'uploads'
folder inside the 'website' folder and change the link accordingly, it would
work.
It works fine if I move the 'uploads' folder back on the web site, but
as it needs to be chmod 777, it is now open to everyone, and might
become a security issue on my server.

I read that by putting it outside the web folder, it could not be access
by browsing, but I can not find any way to retrieve the folder, even
that I can put them without any problem.
As www.mywebsite.com and the website folder should be the same ... I take it
that having <img src='../../uploads/images/test.gif'makes no difference?

Apr 17 '07 #3
Emmanuel Petit wrote:
Sean a écrit :
>>
I am sure that there may be another solution, but I think that you
cannot path back outside of your webserver. I'd bet that if you moved
the 'uploads' folder inside the 'website' folder and change the link
accordingly, it would work.
It works fine if I move the 'uploads' folder back on the web site, but
as it needs to be chmod 777, it is now open to everyone, and might
become a security issue on my server.

I read that by putting it outside the web folder, it could not be access
by browsing, but I can not find any way to retrieve the folder, even
that I can put them without any problem.
>As www.mywebsite.com and the website folder should be the same ... I
take it that having <img src='../../uploads/images/test.gif'makes no
difference?

The problem is that when you try to load the image, the user is
browsing. From the request to the server, there is absolutely no
difference between:

http://www.example.com/image.jpg

and loading a page with

<img src="/image.jpg"...>

Both result in a GET request from the browser to the server to retrieve
the image.

You could do something like create a php file which serves the images
from the other folder, but that's the hard way.

The real problem is why do you think the images have to be chmod 777.
That's absolutely incorrect. All they need is 400 and owned by the
webserver's userid, for instance.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 17 '07 #4
Jerry Stuckle <js*******@attglobal.netwrote in
news:4e******************************@comcast.com:

You could do something like create a php file which serves the images
from the other folder, but that's the hard way.
You can make it all fancy-like, or simple.... depending on what you
need. But if you have the GD library and you're set on keeping images
above the webserver, you can do something like this... I'll call this
file "imagedisplay.php";

<?php

/*
if you wanted, you could have the database figure out which image to get
based on a 'file key' or something, or another db call... for this
example, i'm putting the image name right in the code.
*/

$vImg = "donut.jpg";

header("Content-type: image/jpeg");
if(file_exists($vImg)) {
$img_handle = imagecreatefromjpeg($vImg) or die("");
ImageJpeg($img_handle);
}

?>

Voila.

In your code, it's just:

<img src="imagedisplay.php?vKey=xyydjaj" alt="My Image" />


Apr 17 '07 #5
Good Man <he***@letsgo.comwrote in
news:Xn************************@216.196.97.131:

$vImg = "donut.jpg";
Actually, $vImg would likely be
"/home/protected/directory/donut.jpg"
Apr 17 '07 #6
Good Man a écrit :
Good Man <he***@letsgo.comwrote in
news:Xn************************@216.196.97.131:

>$vImg = "donut.jpg";

Actually, $vImg would likely be
"/home/protected/directory/donut.jpg"
Thank you all for your help, I shall put that on test, and see how I get
from there...
Apr 17 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Al Smith | last post by:
I need help in implementing proper error handling. I am trying to upload a file based on the sample code below. The code works well except if the file selected is too big. I do know about the...
4
by: Manu | last post by:
I want my user to upload a file to the site. Let us say a word file to be saved in the database for other users of the site to use. How can this be done? Is there a web control for that?
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
3
by: Mike Kelly | last post by:
Hi. I've built a page using standard ASP.NET 2.0 features and when I upload a large file (>20MB) to our intranet server, I get a paltry 100KB/s on our 100Mb/s LAN. Simply copying the file, I get...
1
by: Bob | last post by:
I've made an upload function saving to a specific folder and dropdownlist reading and listing files from the folder. When I upload, the list is rendered a second time in the dropdownlist with the...
2
by: David | last post by:
I am attempting to upload files via. PHP 4.4.4. The '$_FILES' resolves to '/tmp/phpey9MpD', but when I go to the /tmp dir. I do not see any php* file. Could this be a issue with PHP or unix...
0
by: Tim Payne | last post by:
I have an odd permissions issue with uploading files to a windows 2003 server. I have a reasonably unusual setup. We have a php website, running through IIS that was written to use mod_rewrite....
4
by: henribaeyens | last post by:
Hello, I have this question that hopefully some of you guys can answer. So I use the usual mechanism: display form, enter data, browse for file, validate, upload if no errors. Well, something...
2
by: darrel | last post by:
I've written a file-upload application in VB.net. A web form with a FILE field that then uploads the file. Pretty simple. I'm getting a report from the customer that one particular user can't...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.