CHMOD

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

Jay Eff
Forum Newbie
Posts: 20
Joined: Sat Oct 26, 2002 11:35 am

CHMOD

Post 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.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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
Jay Eff
Forum Newbie
Posts: 20
Joined: Sat Oct 26, 2002 11:35 am

Post 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
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

try changing 0777 to 777
Jay Eff
Forum Newbie
Posts: 20
Joined: Sat Oct 26, 2002 11:35 am

Post by Jay Eff »

still getting the warning
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

did you put the full path of the directory?

is the file chmoded proprly?
Jay Eff
Forum Newbie
Posts: 20
Joined: Sat Oct 26, 2002 11:35 am

Post by Jay Eff »

the script chmods it to 666, isn't that right?
Jay Eff
Forum Newbie
Posts: 20
Joined: Sat Oct 26, 2002 11:35 am

Post 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
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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');
?>
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

weird thing

Post 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.
Jay Eff
Forum Newbie
Posts: 20
Joined: Sat Oct 26, 2002 11:35 am

Post 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.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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
Jay Eff
Forum Newbie
Posts: 20
Joined: Sat Oct 26, 2002 11:35 am

Post by Jay Eff »

/home/jay-effc/public_html/bossfoobared
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Post Reply