Page 1 of 2

CHMOD

Posted: Sat Oct 26, 2002 11:35 am
by Jay Eff
I am working on a full file manager for Jay-Eff.com and I have come to a problem. How do I CHMOD a directory with PHP. I have tried:

Code: Select all

<?php
chmod ("$dir", 0777);
?>
please help, i would love to get this done.

Posted: Sat Oct 26, 2002 12:36 pm
by hob_goblin
try something like:

Code: Select all

<?
exec("chmod 0777 dir");
?>

0777 being the permissions, and dir being the path to the directory

Posted: Sat Oct 26, 2002 12:58 pm
by Jay Eff
That works! But now I have another problem:

Code: Select all

&lt;?php
  $fp = fopen("$homedir/$dir/$file","w");
?&gt;
this is the editor part of the script. that line should open the file to be saved. but i get this error:
Warning: fopen("/home/jay-effc/public_html/boss/index.php", "w") - Permission denied in /home/jay-effc/public_html/boss/editor.php on line 13
grrr. fickle php

Posted: Sat Oct 26, 2002 1:00 pm
by hob_goblin
try changing 0777 to 777

Posted: Sat Oct 26, 2002 1:07 pm
by Jay Eff
still getting the warning

Posted: Sat Oct 26, 2002 1:12 pm
by hob_goblin
did you put the full path of the directory?

is the file chmoded proprly?

Posted: Sat Oct 26, 2002 1:19 pm
by Jay Eff
the script chmods it to 666, isn't that right?

Posted: Sat Oct 26, 2002 1:28 pm
by Jay Eff
i just checked and the directory chmod exec is not chmoding. it doesn't give an error, but it also does not chmod the directory

Posted: Sat Oct 26, 2002 1:32 pm
by hob_goblin
did you make sure to put the full path?

try something like

Code: Select all

<?
exec("CHMOD 0777 /path/to/dir") or die('foobared');
?>

weird thing

Posted: Sat Oct 26, 2002 1:34 pm
by phpScott
on php.net under mkdir, i know you using files, it mentions in one of the posts that php might not let you make a file with 777 permissions, so it suggest that you make the file first then change its persmissions.
The other problem might be that the directory structure leading to the specified directory must have the same persmissions.

Posted: Sat Oct 26, 2002 1:42 pm
by Jay Eff

Code: Select all

&lt;?php
  $ch = "$homedir/$dir";
  exec("CHMOD 0777 $ch") or die('foobared');
  $f  = "$homedir/$dir/$file";
  exec("chmod 0777 $f");
  $fp = fopen($f,"w");
?&gt;
the directory i am trying to chmod is /home/jay-effc/public_html/boss. everything i try, nothing works.

Posted: Sat Oct 26, 2002 1:46 pm
by hob_goblin

Code: Select all

&lt;?php
  $ch = "$homedir/$dir";
  echo $ch;
  exec("chmod 777 $ch") or die('foobared');
  $f  = "$homedir/$dir/$file";
  chmod($f, 777);
  $fp = fopen($f,"w");
?&gt;
try that
tell me what it outputs

Posted: Sat Oct 26, 2002 1:49 pm
by Jay Eff
/home/jay-effc/public_html/bossfoobared

Posted: Sat Oct 26, 2002 1:57 pm
by hob_goblin
I really have never used Linux, so i don't know about it's commands.

Maybe someone can come along and provide the proper way to do it..

I know you have to use exec()...

but now, from php's manual..
Again, never forget that the file mode must be passed as an *octal* value, not as a decimal number or a string. So it must be 0755 instead of 755 or "755", for example. This is a very common pitfall.

Posted: Sat Oct 26, 2002 2:27 pm
by Takuma