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中设置index.php文件为只读的方法

为index.php文件设置只读属性后,木马就没权限给你文件末尾追加广告了。下面我们看具体的代码,设置index.php只读: 复制代码 代码如下:<?phpfunction se...

PHP5.3新特性小结

本文总结分析了PHP5.3新特性。分享给大家供大家参考,具体如下: 1、命名空间 解决了类,函数和常量名冲突的问题 2、静态绑定 继承时父类可以直接调用子类重写父类的方法 class...

php实现的递归提成方案实例

本文实例讲述了php实现的递归提成方案。分享给大家供大家参考,具体如下: 最近CRM项目中用到了递归提成的方案,分析如下: SQL语句如下: CREATE TABLE `crm_pr...

利用discuz自带通行证整合dedecms的方法以及文件下载

利用discuz自带通行证整合dedecms的方法以及文件下载

整合discuz的通行证:利用discuz自带通行证整合dede的方法以及文件下载首先感谢柏拉图提供这么好的免费程序在论坛上看到大家很多都想整合discuz。我想柏拉图肯定会弄一个非常完...

preg_match_all使用心得分享

preg_match_all — 进行全局正则表达式匹配 说明 复制代码 代码如下:int preg_match_all ( string pattern, string subject...