section31 Posted January 6, 2004 Posted January 6, 2004 hey, anyone ever use the chmod php function. I'm getting some strange results. Ok, first I'm unable to chmod any file that I upload onto the server. But lets say I create one in the script using fopen(File, 'w+), then chmod it immediately after creation it works. Any idea why its not working properly. Sample Code >$file="test.txt"; if(!file_exists($file)) { if(!fopen($file, 'w+')) die("<b>Could not create $file as database, CHMOD your directory to the appropriate permissions.</b>"); echo"<b>Created $file since it didn't exist!!!</b><br />"; } if(!is_writable($file) || !is_executable($file)) if(chmod($file, 0777)) echo"<b>Changed $file permissions to 777!!!</b><br />"; else die("<b>Could not chmod $file to 777, please do this manually!!!</b>"); Quote
borfast Posted January 7, 2004 Posted January 7, 2004 You can't chmod files uploaded via FTP because their owner is the user which uploaded them and the user PHP acts like is another one, so it can't change other users' files. If you create a file with a PHP script, it's owner will be the user PHP runs as, so when you try to chmod it, there's nothing wrong with it. Quote
section31 Posted January 7, 2004 Author Posted January 7, 2004 Ah i c, so is there any way to change that id. I'm guessing not otherwise u would've given me that tip. BTW, where can i get more info about that UID, GID and Sticky option for chmoding. Thanks for the reply, Dave Quote
glassgorilla Posted January 7, 2004 Posted January 7, 2004 chown changes the user. i have never gotten it to work and i don't know what php runs as on tch, i think it's usually 'nobody' though. but php might not be able to change the owner because it isn't the owner in the first place. from manual: chown -- Changes file ownerDescription bool chown ( string filename, mixed user) Attempts to change the owner of the file filename to user user (specified by name or number). Only the superuser may change the owner of a file. Returns TRUE on success or FALSE on failure. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.