Page 1 of 1

AFTER I USE UPLOAD SCRIPT, CAN'T VIEW IMAGE "FORBIDDEN"

Posted: Fri Jun 06, 2008 8:39 pm
by mirra1515
I created a file upload script for a web project that I am working on. It works wonderfully...you upload the file and it appears on the server.

BUT...when you go to view it...say using "http://www.mysite.com/uploads/image.jpg"...it says "forbidden" access denied and so on. This must have something to do with the fact that the image was uploaded using my script since images uploaded using the FTP can be viewed no problem.

Any ideas on what could be causing this problem? Thanks!

My image upload script looks like this:

Code: Select all

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] <= 20000))
  {
      if ($_FILES["file"]["error"] > 0)
      {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
      }
      else
      {  
        if (file_exists("upload/" . $_FILES["file"]["name"]))
        {
          echo $_FILES["file"]["name"] . " already exists. ";
        }
        else
        {
            //Upload file
            $ext = explode("/", $_FILES["file"]["type"]);
            if ($ext[0] == "image") {
                move_uploaded_file($_FILES["file"]["tmp_name"],
                "fileUploads/" . $_FILES["file"]["name"]);
            }
         }
      }
  }
else
{
  echo $_FILES["file"]["type"] . " " . $_FILES["file"]["size"] . "<br>";
  echo "Invalid file";
}
 
?>
Then my simple html to view the image is:

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

Re: AFTER I USE UPLOAD SCRIPT, CAN'T VIEW IMAGE "FORBIDDEN"

Posted: Fri Jun 06, 2008 10:58 pm
by LSJason
Have you tried chmodding the file?

http://ch2.php.net/chmod

Re: AFTER I USE UPLOAD SCRIPT, CAN'T VIEW IMAGE "FORBIDDEN"

Posted: Fri Jun 06, 2008 11:45 pm
by califdon
Where are you uploading your files to? Is it a directory within the web server document root? If not, the web server won't be able to serve it in response to an HTTP request.

Re: AFTER I USE UPLOAD SCRIPT, CAN'T VIEW IMAGE "FORBIDDEN"

Posted: Sat Jun 07, 2008 12:17 am
by mirra1515
Thanks for the replies,

I just tried CHMOD and it didn't work...maybe I'm using it wrong though?

Right above where I am trying to display the image ("<img src="...">) I have:

<?php chmod("/uploads/AOE-15.jpg", 0644); ?>

All I get is this error:

Warning: chmod(): No such file or directory in /var/www/html/index.php on line 460

I know the directory exists...so I don't know what the problem is.

In response to the second reply...I do believe this is all located in my root directory. the uploads folder is within the same directory as my index.php page and all of my other files.

Re: AFTER I USE UPLOAD SCRIPT, CAN'T VIEW IMAGE "FORBIDDEN"

Posted: Sat Jun 07, 2008 12:17 am
by Benjamin
No need to type in all caps btw.

Re: AFTER I USE UPLOAD SCRIPT, CAN'T VIEW IMAGE "FORBIDDEN"

Posted: Sat Jun 07, 2008 12:19 am
by mirra1515
Sorry, my mistake :|

Re: AFTER I USE UPLOAD SCRIPT, CAN'T VIEW IMAGE "FORBIDDEN"

Posted: Sat Jun 07, 2008 4:08 am
by madan koshti
Hi ,

where are you moving the uploaded file...?

check your code :
move_uploaded_file($_FILES["file"]["tmp_name"], "fileUploads/" . $_FILES["file"]["name"]);

and your are trying to check in uploads directory ?:
<img src="uploads/image.jpg">

Re: AFTER I USE UPLOAD SCRIPT, CAN'T VIEW IMAGE "FORBIDDEN"

Posted: Sun Jun 08, 2008 12:21 am
by mirra1515
Thanks for pointing that out...just a typo sadly, not the the route of the problem.

To clarify, the directory used in my code is "uploads".

Thanks though, good catch!

Re: AFTER I USE UPLOAD SCRIPT, CAN'T VIEW IMAGE "FORBIDDEN"

Posted: Sun Jun 08, 2008 7:04 pm
by helraizer
try in the chmod from:

/uploads/

to either

./uploads/ or uploads/

Do you have restrictions on the folder itself or is it just the image?