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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mirra1515
Forum Commoner
Posts: 29
Joined: Fri Apr 25, 2008 3:17 am

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

Post 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">
LSJason
Forum Commoner
Posts: 45
Joined: Mon May 12, 2008 4:43 pm

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

Post by LSJason »

Have you tried chmodding the file?

http://ch2.php.net/chmod
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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.
User avatar
mirra1515
Forum Commoner
Posts: 29
Joined: Fri Apr 25, 2008 3:17 am

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

Post 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.
Last edited by mirra1515 on Sat Jun 07, 2008 12:18 am, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

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

Post by Benjamin »

No need to type in all caps btw.
User avatar
mirra1515
Forum Commoner
Posts: 29
Joined: Fri Apr 25, 2008 3:17 am

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

Post by mirra1515 »

Sorry, my mistake :|
madan koshti
Forum Commoner
Posts: 50
Joined: Fri Jun 06, 2008 4:25 am

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

Post 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">
User avatar
mirra1515
Forum Commoner
Posts: 29
Joined: Fri Apr 25, 2008 3:17 am

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

Post 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!
helraizer
Forum Commoner
Posts: 31
Joined: Thu Jun 05, 2008 8:20 pm

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

Post 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?
Post Reply