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使用Jpgraph绘制柱形图的方法

php使用Jpgraph绘制柱形图的方法

本文实例讲述了php使用Jpgraph绘制柱形图的方法。分享给大家供大家参考。具体实现方法如下: <?php include ("src/jpgraph.php");...

PHP实现排序堆排序(Heap Sort)算法

PHP实现排序堆排序(Heap Sort)算法

算法引进: 在这里我直接引用《大话数据结构》里面的开头: 在前面讲到 简单选择排序 ,它在待排序的 n 个记录中选择一个最小的记录需要比较 n - 1 次,本来这也可以理解,查找第一个数...

php使用json-schema模块实现json校验示例

本文实例讲述了php使用json-schema模块实现json校验。分享给大家供大家参考,具体如下: 客户端和服务端的http信息传递,采用json几乎成了标配。json格式简单,易于处...

php图片处理:加水印、缩略图的实现(自定义函数:watermark、thumbnail)

废话不说了,贴代码: 复制代码 代码如下: <?php /************************************ //函数: watermark($bigimg,...

php学习之function的用法

1,申明函数 在PHP中,定义函数的方法同其他编程语言几乎一样.下面是PHP申明函数的语法结构: 复制代码 代码如下: Function function_name($argument1...