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

yipeiwu_com6年前PHP代码库

本文实例讲述了PHP对文件夹递归执行chmod命令的方法。分享给大家供大家参考。具体分析如下:

这里对文件夹和文件递归执行chmod命令来改变执行权限

<?php
  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);
  }
?>

希望本文所述对大家的php程序设计有所帮助。

相关文章

php实现的树形结构数据存取类实例

本文实例讲述了php实现的树形结构数据存取类。分享给大家供大家参考。 具体实现代码如下: 复制代码 代码如下:<?php /**  * Tanphp fram...

PHP通过GD库实现验证码功能示例

PHP通过GD库实现验证码功能示例

本文实例讲述了PHP通过GD库实现验证码功能。分享给大家供大家参考,具体如下: 首先看看实现的效果: 具体实现: <?php /*PHP实现验证码*/ session...

php 一元分词算法

复制代码 代码如下:/** * 一元分词算法 * UTF8编码下一个字符如果首字符ASCII码不大于192则只占1个字节 * 如果首字符ASCII码大于192小于224则占用2个字节,否...

php显示指定目录下子目录的方法

本文实例讲述了php显示指定目录下子目录的方法。分享给大家供大家参考。具体实现方法如下: <?php echo "<h2>subdirs in dir<...

PHP容易被忽略而出错陷阱 数字与字符串比较

0 与任意非数字(或者说,不可转化为数字的字符)前导的字符串比较(操作符为==), 均返回 true. 原因是, 数字与字符串比较时, 先尝试将字符串转换为数字, 再比较, 一个不能转...