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实现带进度条的Ajax文件上传功能示例

PHP实现带进度条的Ajax文件上传功能示例

本文实例讲述了PHP实现带进度条的Ajax文件上传功能。分享给大家供大家参考,具体如下: 之前分享了一篇关于 php使用FileApi实现Ajax上传文件 的文章,里面的Ajax文件上传...

Json_decode 解析json字符串为NULL的解决方法(必看)

从APP端或从其他页面post,get过来的数据一般因为数组形式。因为数组形式不易传输,所以一般都会转json后再发送。本以为发送方json_encode(),接收方json_decod...

PHP使用pdo实现事务处理操作示例

本文实例讲述了PHP使用pdo实现事务处理操作。分享给大家供大家参考,具体如下: 使用事务的好处: 举个例子:银行用户A向用户B转账100元,这个操作被分为两个步骤: (1)A的账户余额...

php定义一个参数带有默认值的函数实例分析

本文实例分析了php定义一个参数带有默认值的函数用法。分享给大家供大家参考。具体分析如下: php的函数参数可以指定默认值,指定默认值后,调用时如果不给该参数赋值,则该参数就使用默认值...

盘点PHP和ASP.NET的10大对比!

盘点PHP和ASP.NET的10大对比!

在网上论坛,总是有成百上千的文章和帖子在讨论 PHP 和 ASP.NET,究竟谁才是更好的平台?不过很可惜,大部分人的观点总是带有偏见的,人们总会有意无意地推广自己喜欢的语言。 此外,如...