Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permissions error when uploading

Status
Not open for further replies.

jgd123456

Programmer
Nov 3, 2006
19
GB
Hi, i'm trying to upload a file but when i view the file i get the error:

You don't have permission to access /images/image.gif on this server.

The code works perfectly locally but not online. I checked the permissions on the image and it was set to 600 and when i set it to 644 (via ftp) it displayed fine.

Therefore i figured i could change the permissions using php so i added a chmod line below my move_uploaded_file like so:

move_uploaded_file($temp_file, $path . $file_name);
chmod($path . $file_name, 644);

But this gave me a permissions error even though i have set my images folder to 777.

Appreciate if someone could help. Thanks
 
try setting the umask to 0 before performing the chmod.

you should also prepend the mode with a 0 to force it into octal rather than decimal.
Code:
$u = umask(0);
move_uploaded_file($temp_file, $path . $file_name);
chmod($path . $file_name, 0644);

but the problem has probably been caused by the directory itself having been created with faulty credentials.
 
I forgot to add a last line, to reset the umask or further operations.

Code:
umask($u);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top