Page 1 of 1

Making folder writable to PHP.

Posted: Thu Apr 17, 2008 2:42 am
by jlising
Hello,

I have a script online use to generate a zip file and write it in a folder e.g.: admin/export.
I believe changing export folder to writable permission globally is not advisable because any user can modify or can delete the files.

I came up in a scenario. First, leave the folder in read only mode. Second, before writing a file (using php file system functions) in the folder change the permission to writable. Lastly, after writing the file to the folder restore the folder permission to read only again.

Right now I have a problem with this method. I cannot write file to the export folder. I believe the cause of the error is the folder is still in read only mode.

Can anyone help me to solve this issue? Do anyone has different approach?

Many Thanks!
Jess

Re: Making folder writable to PHP.

Posted: Thu Apr 17, 2008 4:32 am
by Kieran Huggins
chown the folder to the same user that apache runs under (www-data on debian systems) - then you can give only that user permission to write to that directory.

Re: Making folder writable to PHP.

Posted: Thu Apr 17, 2008 4:42 am
by jlising
Hi Kieran,

Can you give me a php code fragment using the chown and how to change the permission?
Please....

Many Thanks!
Jess

Re: Making folder writable to PHP.

Posted: Thu Apr 17, 2008 8:44 am
by John Cartwright
There are examples in the manual, see http://ca.php.net/chown

Re: Making folder writable to PHP.

Posted: Thu Apr 17, 2008 3:32 pm
by VladSun
jlising wrote:Hi Kieran,

Can you give me a php code fragment using the chown and how to change the permission?
Please....

Many Thanks!
Jess
Only the superuser may change the owner of a file.
So, in order to chown file you (i.e. the Apache user) must be root. And ... DON'T run Apache as root. The same applies to chmod... So, your scenario doesn't make sense.

Kieran Huggins told you - log in as root, change the directory owner and permissions to Apache user.

If you are on shared hosting, most probably there is nothing you can do - just set the permissions to 0777 (because usually the files are owned by your ftp user, not by the Apache user). And don't worry - your hosting provider must have secured access to your files by other users.