Jump to content

Recommended Posts

Posted

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>");

Posted

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.

Posted

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

Posted

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 owner

Description

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...