php chmod function

liunx

Guest
hey, anyone ever use the chmod php function. I'm getting some strange results. <br /><br />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. <br /><br />Sample Code<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$file="test.txt";<br />if(!file_exists($file))<br />    {<br />      if(!fopen($file, 'w+')) die("<b>Could not create $file as database, CHMOD your               directory to the appropriate permissions.</b>");  <br />      echo"<b>Created $file since it didn't exist!!!</b><br />";  <br />    }<br />if(!is_writable($file) || !is_executable($file))<br />  if(chmod($file, 0777)) echo"<b>Changed $file permissions to 777!!!</b><br />";<br />  else die("<b>Could not chmod $file to 777, please do this manually!!!</b>");<!--c2--></div><!--ec2--><!--content-->
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.<!--content-->
Ah i c, so is there any way to change that id. I'm guessing not otherwise u would've given me that tip. <br /><br />BTW, where can i get more info about that UID, GID and Sticky option for chmoding. <br /><br />Thanks for the reply,<br />Dave<!--content-->
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:<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->chown -- Changes file owner<br />Description<br />bool chown ( string filename, mixed user)<br /><br /><br />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. <br /><br />Returns TRUE on success or FALSE on failure.<!--QuoteEnd--></div><!--QuoteEEnd--><!--content-->
 
Back
Top