chmod function not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
noguru
Forum Commoner
Posts: 61
Joined: Thu Jun 06, 2002 4:03 am
Location: Just north of the City Of Gold, Land of Milk and Honey

chmod function not working

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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

Code: Select all

<?php system('who') ?>
User avatar
noguru
Forum Commoner
Posts: 61
Joined: Thu Jun 06, 2002 4:03 am
Location: Just north of the City Of Gold, Land of Milk and Honey

Post 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!
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post 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.
User avatar
noguru
Forum Commoner
Posts: 61
Joined: Thu Jun 06, 2002 4:03 am
Location: Just north of the City Of Gold, Land of Milk and Honey

Post 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?
Post Reply