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程序设计有所帮助。

相关文章

学习使用curl采集curl使用方法

复制代码 代码如下: <?php $cookie_jar = tempnam('./tmp','cookie'); $ch = curl_init(); curl_setopt($...

WordPress中重置文章循环的rewind_posts()函数讲解

有些时候,在索引页中(首页、分类文章、标签文章、作者文章索引……)提前进入 WordPress 文章循环中( Loop ),以获得一些我们想要获得的信息,但 WP 中,单一页面一般只会一...

PHP实现的字符串匹配算法示例【sunday算法】

本文实例讲述了PHP实现的字符串匹配算法————sunday算法。分享给大家供大家参考,具体如下: Sunday算法是Daniel M.Sunday于1990年提出的字符串模式匹配。其核...

刷新PHP缓冲区为你的站点加速

在当前 PHP 版本的默认配置下,“输出缓冲(Output Buffering)”是被打开的。旧版本则不是这样,在旧版本的 PHP 中,字符串在每次被输出的时候(通过 echo 或 pr...

PHP版QQ互联OAuth示例代码分享

由于国内QQ用户的普遍性,所以现在各大网站都尽可能的提供QQ登陆口,下面我们来看看php版,给大家参考下 /** * QQ互联 oauth * @author dyllen *...