Recursive Chmod not working PHP

折月煮酒 提交于 2019-12-11 17:51:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!