PHP对文件夹递归执行chmod命令的方法

yipeiwu_com5年前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生成xml简单实例代码

当处理基于XML应用程序时,开发者经常需要建立XML编码数据结构。例如,Web中基于用户输入的XML状态模板,服务器请求XML语句,以及基于运行时间参数的客户响应。 尽管XML数据结构的...

php实现的Timer页面运行时间监测类

本文实例讲述了php实现的Timer页面运行时间监测类及其用法,是一款非常实用的PHP类文件。分享给大家供大家参考。具体分析如下: 该php Timer页面运行时间监测类,可按不同key...

详解php中空字符串和0之间的关系

前言 最近在处理关于经纬度的问题时,在建表的时候,选择用字符串varchar存储经度、纬度。为以后的问题埋下伏笔。下面话不多说,我们来看看详细的介绍。 $_x=$row["x"];...

实用PHP会员权限控制实现原理分析

实用PHP会员权限控制实现原理分析

我的通用权限系统设计是更换权限时候尽量不要涉及到代码修改,来自chinaunix论坛,今天转过来看看。希望对大家有所帮助,对PHP100的朋友有个很高的提升。 复制代码 代码如下: /*...

详解WordPress开发中get_header()获取头部函数的用法

函数意义详解 从当前主题调用header.php文件。是不是很简单?好吧,如果你是新手的话这里要提醒一下,这里的get和get_children()、get_category中的get略...