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实现简单的上传进度条

php实现简单的上传进度条

Web上传文件的三种解决方案分享给大家: 这里我要使用的是form法。通过为表单元素设置enctype=”multipart/form-data”属性,让表单提交的数据以二进制编码的方...

php之readdir函数用法实例

本文实例讲述了php中readdir函数用法。分享给大家供大家参考。具体用法分析如下: 定义和用法:readdir() 函数返回由 opendir() 打开的目录句柄中的条目,若成功,则...

php编程每天必学之表单验证

本文实例讲解了php表单验证的实现方法,分享给大家供大家参考,具体内容如下 1.PHP表单处理 welcome.html <html> <body> &l...

PHP 删除文件与文件夹操作 unlink()与rmdir()这两个函数的使用

先看一下代码 复制代码 代码如下: <? function deldir($dir) { //先删除目录下的文件: $dh=opendir($dir); while ($file=...

thinkphp如何获取客户端IP

thinkphp框架中系统内置了get_client_ip方法用于获取客户端的IP地址,使用示例: $ip = get_client_ip(); 除了thinkphp内置get_cl...