问题
I have the below PHP function that should recursively chmod one of the dir's on my server.
For some reason it's not working - i know the path to the dir is correct as i've tested it with a quick script that just prints out the files within that dir.
$root_tmp = '/tmp/mixtape2';
chmod_r($root_tmp);
function chmod_r($Path) {
$dp = opendir($Path);
while($File = readdir($dp)) {
if($File != "." AND $File != "..") {
if(is_dir($File)){
chmod($File, 0777);
chmod_r($Path."/".$File);
}else{
chmod($Path."/".$File, 0777);
}
}
closedir($dp);
}
Any ideas?
回答1:
chmod($Path.'/'.$File, 0777);
You must put full path to chmod
回答2:
Your PHP script is executed by the webserver, which most probably has its own user on your system. Since the files you are trying to chmod() are owned by root, you don't have the right to chmod them. You need to go into your filesystem first, and chown these files to the correct user and group.
来源:https://stackoverflow.com/questions/16211033/recursive-chmod-not-working-php