本文介绍了递归设置所有文件和文件夹的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想递归设置文件夹和文件的权限.文件夹应该有750个,文件应该有644个.我发现并进行了一些修改.这会行吗?

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?

<?php

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

?>

推荐答案

为什么不为此使用查找工具?

Why don't use find tool for this?

exec ("find /path/to/folder -type d -exec chmod 0750 {} +");
exec ("find /path/to/folder -type f -exec chmod 0644 {} +");

这篇关于递归设置所有文件和文件夹的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 08:17