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

相关文章

Laravel中扩展Memcached缓存驱动实现使用阿里云OCS缓存

Laravel 是我最近用得非常多而且越用就越喜欢的一款PHP框架,由于没有向下兼容的历史包袱,完全面向对象的风格,借助 Facades 优雅的IoC Container 实现,采用 C...

php使用explode()函数将字符串拆分成数组的方法

本文实例讲述了php使用explode()函数将字符串拆分成数组的方法。分享给大家供大家参考。具体分析如下: explode()函数:字符串拆分成数组 示例代码如下: <...

ThinkPHP中公共函数路径和配置项路径的映射分析

本文实例分析了ThinkPHP中公共函数路径和配置项路径的映射。分享给大家供大家参考。具体分析如下: ThinkPHP中在使用公共函数时(单一入口文件对应独立的项目),在Common文件...

PHP生成条形图的方法

PHP生成条形图的方法

本文实例讲述了PHP生成条形图的方法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下: <?php   // create an array of...

php获取当前页面完整URL地址

使用PHP编写程序的时候,我们常常想要获取当前页面的URL。下面提供一个用于获取当前页面URL的函数以及使用方法: 示例一: <?php // 说明:获取完整URL...