Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

PHP upload question

I have a question about uploading files with PHP that I was hoping someone could help me with. I am able to upload a .txt file to a directory I created called uploads, however when I open the file with my text editor it is blank. When I list the files in this directory with the ls la command it says the owner of the file is apache and not my username. The permission are rw---, so I do not think I have read permission since I am not the owner, however it will not let me change the permissions on the file. It says, changing permissions is not permitted.
[561 byte] By [leafdodger] at [2007-11-11 9:48:52]
# 1 Re: PHP upload question
Your webserver, apache, created the file, therefore it has read/write access. When you upload the file, use chmod to allow your username to have rw- access.

http://us2.php.net/manual/en/function.chmod.php

You may want to consider using a 3rd party uploading tool, especially if uploading lots of images, as they will help prevent future headaches. My favorite is upload.php by colin verot @ http://www.verot.net;
cyberlogi at 2007-11-11 23:34:34 >
# 2 Re: PHP upload question
You can create script with chown or chmod command in PHP, which chmod or chown your "locked" file.
After that execute that script with http request.
Apache will do chown or chmod the file with right perrmissions, because apache user is the owner of the file.
zdrsoft at 2007-11-11 23:35:40 >