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
Post
by Jay Eff » Sat Oct 26, 2002 11:35 am
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.
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Sat Oct 26, 2002 12:36 pm
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 » Sat Oct 26, 2002 12:58 pm
That works! But now I have another problem:
Code: Select all
<?php
$fp = fopen("$homedir/$dir/$file","w");
?>
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
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Sat Oct 26, 2002 1:00 pm
try changing 0777 to 777
Jay Eff
Forum Newbie
Posts: 20 Joined: Sat Oct 26, 2002 11:35 am
Post
by Jay Eff » Sat Oct 26, 2002 1:07 pm
still getting the warning
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Sat Oct 26, 2002 1:12 pm
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 » Sat Oct 26, 2002 1:19 pm
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 » Sat Oct 26, 2002 1:28 pm
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
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Sat Oct 26, 2002 1:32 pm
did you make sure to put the full path?
try something like
Code: Select all
<?
exec("CHMOD 0777 /path/to/dir") or die('foobared');
?>
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Sat Oct 26, 2002 1:34 pm
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 » Sat Oct 26, 2002 1:42 pm
Code: Select all
<?php
$ch = "$homedir/$dir";
exec("CHMOD 0777 $ch") or die('foobared');
$f = "$homedir/$dir/$file";
exec("chmod 0777 $f");
$fp = fopen($f,"w");
?>
the directory i am trying to chmod is /home/jay-effc/public_html/boss. everything i try, nothing works.
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Sat Oct 26, 2002 1:46 pm
Code: Select all
<?php
$ch = "$homedir/$dir";
echo $ch;
exec("chmod 777 $ch") or die('foobared');
$f = "$homedir/$dir/$file";
chmod($f, 777);
$fp = fopen($f,"w");
?>
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 » Sat Oct 26, 2002 1:49 pm
/home/jay-effc/public_html/bossfoobared
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Sat Oct 26, 2002 1:57 pm
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.
Takuma
Forum Regular
Posts: 931 Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:
Post
by Takuma » Sat Oct 26, 2002 2:27 pm