Page 1 of 1
chmod function not working
Posted: Fri Aug 30, 2002 7:15 am
by noguru
Hi
I need to change the permissions for a directory on unix through php code, but I get the error message "Not owner". My code is as follows:
$pathonserver = "/usr/local/apache/htdocs/mydir";
chmod($pathonserver,0646);
I need to copy a file (using the copy function) from one directory to another, but I will need write access to "other" user in order to do so.
All I need is to give write access to the directory, copy the file and then remove it again.
Thanks
Posted: Fri Aug 30, 2002 7:40 am
by volka
only the owner and root have the permission to change file permissions (what would be the purpose of such a mechanism otherwise

)
if unsure under which effective user id your script is running try
Posted: Fri Aug 30, 2002 8:00 am
by noguru
The php script and the directory has got the same owner. System('who') confirms this, right?:
root pts/0 Aug 30 08:48
rudi pts/3 Aug 30 09:07
rudi pts/3 Aug 30 09:07
(although I don't know why system('who') shows "root" as well).
The directory belongs to the user "rudi" as well as this php page. Why would I then get the error "Not owner"?
Maybe I'm way off track here. Please help!
Posted: Fri Aug 30, 2002 8:06 am
by mikeq
It is not so much the owner of the PHP page, but the user that is running the PHP page, so the webserver may not be running as the user that owns the files.
You may need to get shell access to the command line on the server to change permissions, or maybe some ftp clients can change permissions.
Posted: Fri Aug 30, 2002 8:29 am
by noguru
Yes on the command line I can change the permission, but I wanted to change it using php. I am developing a web interface to be used by one or two users here to upload their html files to their ftp directory on unix. This is not just an alternative to a ftp client, but also these html pages need to be edited programmatically, adding an include file at the top and renaming from .htm to .php. Everything was working fine when the directory had write access to "other" users (757), but when I removed write access (755) using the command-line and tried to do it in php, it gave permission errors.
The transfer and editing takes place from the /var/tmp/ directory to the actual ftp directory (bizarre I know...). This results in yet another problem: The owner of the uploaded file is now "http", which means the file cannot be overwritten in future by the user using his normal ftp client.
Where am I going wrong?