faild to create path with chmod 777

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
hueman
Forum Newbie
Posts: 2
Joined: Sat Jun 05, 2010 5:00 pm

faild to create path with chmod 777

Post by hueman »

i need to create nested directories with chmod 777, i tried following code but every directory created with chmod 755 in CentOS, in windows this code create directories with chmod 777, whats the problem?

Code: Select all

$dir = "a";
$folders = array('b','c','d');
foreach($folders as $f)
{
   $dir = $dir."/".$f;
   if(!is_dir($dir))
   {
      if(mkdir($dir))
         echo $f.' was created<br>';
      else
         echo 'failed to create '.$f.'<br>';
      if(chmod($dir, 0777))
         echo $f.' chmod converted to 777<br>';
      else
         echo 'failed to convert '.$f.' chmod to 777<br>';
   }
}
i tried to create my path (eg: 'a/b/c/d') with mkdir('a/b/c/d',0777,true) but this code create directories with chmod 755 too, i didnt success to convert chmod to 777 by applying chmod() to every directories, what can i do to create a path like 'a/b/c/d' with chmod 777 for every directories in CentOS?
Last edited by hueman on Sun Jun 06, 2010 4:31 am, edited 2 times in total.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: faild to create path with chmod 777

Post by Eran »

PHP probably does not run in the same group as the process that created the directories (most likely, it is running as 'Unknown' or 'nobody'). You should set PHP to run under the user/group that owns the directories (most likely, apache) in order to apply chmod.
hueman
Forum Newbie
Posts: 2
Joined: Sat Jun 05, 2010 5:00 pm

Re: faild to create path with chmod 777

Post by hueman »

pytrin wrote:PHP probably does not run in the same group as the process that created the directories (most likely, it is running as 'Unknown' or 'nobody'). You should set PHP to run under the user/group that owns the directories (most likely, apache) in order to apply chmod.
thank you for responding me
how can i apply this setting?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: faild to create path with chmod 777

Post by Eran »

Post Reply