set permissions for all files and folders recursively

前端 未结 5 1241
执笔经年
执笔经年 2021-01-31 04:59

I want to recursively set the folder and file permissions. Folders should get 750 and files 644. I found this and made some adaptions. Would this one work?



        
5条回答
  •  独厮守ぢ
    2021-01-31 05:23

    I think yours won't go recursive in case of folders, I fixed this case.

    function chmod_r($Path) {
        $dp = opendir($Path);
         while($File = readdir($dp)) {
           if($File != "." AND $File != "..") {
             if(is_dir($File)){
                chmod($File, 0750);
                chmod_r($Path."/".$File);
             }else{
                 chmod($Path."/".$File, 0644);
             }
           }
         }
       closedir($dp);
    }
    

提交回复
热议问题