PHP递归对文件夹递归执行chmod命令

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
<?

   function recursiveChmod($path, $filePerm=0644, $dirPerm=0755)
   {
      // Check if the path exists
      if(!file_exists($path))
      {
         return(FALSE);
      }
      // See whether this is a file
      if(is_file($path))
      {
         // Chmod the file with our given filepermissions
         chmod($path, $filePerm);
      // If this is a directory...
      } elseif(is_dir($path)) {
         // Then get an array of the contents
         $foldersAndFiles = scandir($path);
         // Remove "." and ".." from the list
         $entries = array_slice($foldersAndFiles, 2);
         // Parse every result...
         foreach($entries as $entry)
         {
            // And call this function again recursively, with the same permissions
            recursiveChmod($path."/".$entry, $filePerm, $dirPerm);
         }
         // When we are done with the contents of the directory, we chmod the directory itself
         chmod($path, $dirPerm);
      }
      // Everything seemed to work out well, return TRUE
      return(TRUE);
   }
?>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:Python3.4图片转换素描

下一篇:php 使用GD库为图片加水印