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使用SAE原生Mail类实现各种类型邮件发送的方法

本文实例讲述了php使用SAE原生Mail类实现各种类型邮件发送的方法。分享给大家供大家参考,具体如下: 用过SAE的都知道,SAE所有服务中,就数Mail服务最不行了,时不时邮件就发不...

Apache实现Web Server负载均衡详解(不考虑Session版)

至少需三台服务器:服务器A:控制服务器服务器B和服务器C:实际执行服务器负载均衡原理:将访问服务器A的请求分发至服务器B和服务器C修改服务器A上apache的http.conf文件: 首...

PHP识别二维码的方法(php-zbarcode安装与使用)

本文实例讲述了PHP识别二维码的方法。分享给大家供大家参考,具体如下: 说明:扩展需要依赖ImageMagick和zbar,安装前先安装这两个软件 1.安装ImageMagick(htt...

PHP使用DOM和simplexml读取xml文档的方法示例

本文实例讲述了PHP使用DOM和simplexml读取xml文档的方法。分享给大家供大家参考,具体如下: 实例  用DOM获取下列xml文档中所有金庸小说的书名,该xml文档所...

PHP命名空间与自动加载类详解

本文实例讲述了PHP命名空间与自动加载类。分享给大家供大家参考,具体如下: 今天我要给大家介绍的是PHP的命名空间 和 自动加载类 我先简单的分开演示 在放在一起 大家请看: 什么是自动...