chmod for php image upload script


#1

Hi all,

I wrote a php script that will upload an image to a folder set to 0777.

However, from my understanding this is not the safest way to upload a file. I was suggested to change the folder back (chmod) to 0755, and use the chmod in my php script before that will set the folder to 0777 while the image is uploaded; and back to 0755 after the process is complete.

I tried writing the script to do this but i received the following error:
chmod(): Operation not permitted in (my file)

Could somebody please review my chmod code and provide a solution?

Code:
chmod("…/image_bin/", 0777);
move_uploaded_file($_FILES[‘file’][‘tmp_name’],’…/image_bin/’.$_FILES[‘file’][‘name’]);
chmod("…/image_bin", 0755);

Thank you!


#2

The PHP script acts as a normal user during the execution. Only the owner of the file or root can change file permissions. You will need to the web user as the owner of the folder if you want to do something like that. The user is usually called www or apache.


#3

Only the owner of the file or root can change file permissions. You will need to the web user as the owner of the folder if you want to do something like that. The user is usually called www or apache.

How do I do this (become the owner or act as the owner)? Via FTP folder properties or code? Do you have a tidbit of code that would help me? I am also interested in file transfer (including renaming, deleting etc.) in general for beginners?

Thanks…


#4

It has been a while. Does anyone know how to do this? Does anyone know the risks of leaving a folder security to 0777?

Please help… :cry:


#5

Golden, after thinking it twice i have some short of “solution” 4 u, ( hope bane doesen’t broke my bones ), i’m a newbie 2 so, the info may be not entirely accurate, forgive me.

1.- try open a pipe to execute a shell script ( i c it some where searching 4 mail() )
2.- MySQL.

hope this helps u some how.

cya & forgiveme 4 the bad english.