views:

133

answers:

2

I have a form that lets users upload a photo of themselves. This seems to work. The photo does exist on the server once uploaded. When I try to access the file I get a "403 forbidden - you don't have permission to access this url on this sever" and also I get "Additionally, a 410 Gone error was encountered while trying to use an ErrorDocument to handle the request."

This is the code I have for uploading the image.

$target_path = "images/";

$target_path = $target_path . basename( $_FILES['uploadpic']['name']);

if(move_uploaded_file($_FILES['uploadpic']['tmp_name'], $target_path))
 {
    echo "The file ". basename( $_FILES['uploadpic']['name']). " has been uploaded";
 } 
else
 {
echo "There was an error uploading the file, please try again!";
 }
A: 

There's chmod() for Unix-like systems.

Be warned that your script will unconditionally overwrite the destination file. Maybe this is what you wanted, but consider what could happen if that $target_path is Web-accessible and a malicious uploads a new 'index.php' or whatever.

Marc B
Yeah that's a good warning. So far I'm leaving it the way it was so i can "review" any uploads before making them active.
creocare
A: 

You must check the configuration of your destination path:

403 forbidden -> You don't have permission to enter that directory...

You need to change the chmod of that directory...

410 Gone error -> The server couldn't found the proper error document to present with the 403 forbidden message (at htaccess you can set this up)

If you don't want this message, you need to create a custom one...

Zuul
how do i change the chmod of that directory?
creocare