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


Posted in PHP onJune 19, 2015

本文实例讲述了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的ASP防火墙
Oct 09 PHP
[原创]PHP中通过ADODB库实现调用Access数据库之修正版本
Dec 31 PHP
php日期转时间戳,指定日期转换成时间戳
Jul 17 PHP
PHP中使用register_shutdown_function函数截获fatal error示例
Apr 21 PHP
反射调用private方法实践(php、java)
Dec 21 PHP
Laravel实现构造函数自动依赖注入的方法
Mar 16 PHP
PHP遍历目录文件的常用方法小结
Feb 03 PHP
php使用PDO获取结果集的方法
Feb 16 PHP
php判断电子邮件是否正确方法
Dec 04 PHP
PHP微信发送推送消息乱码的解决方法
Feb 28 PHP
PHP匿名函数(闭包函数)详解
Mar 22 PHP
PHP中PCRE正则解析代码详解
Apr 26 PHP
php强制用户转向www域名的方法
Jun 19 #PHP
php自动更新版权信息显示的方法
Jun 19 #PHP
php中Snoopy类用法实例
Jun 19 #PHP
php计算整个目录大小的方法
Jun 19 #PHP
php简单计算页面加载时间的方法
Jun 19 #PHP
php实现随机生成易于记忆的密码
Jun 19 #PHP
php根据一个给定范围和步进生成数组的方法
Jun 19 #PHP
You might like
php 三元运算符实例详细介绍
2016/12/15 PHP
JavaScript 空位补零实现代码
2010/02/26 Javascript
基于jquery1.4.2的仿flash超炫焦点图播放效果
2010/04/20 Javascript
javascript实例分享---具有立体效果的图片特效
2014/06/08 Javascript
jQuery简单实现遍历数组的方法
2015/04/14 Javascript
JQuery中两个ul标签的li互相移动实现方法
2015/05/18 Javascript
JS特效实现图片自动播放并可控的效果
2015/07/31 Javascript
在JavaScript的jQuery库中操作AJAX的方法讲解
2015/08/15 Javascript
js带前后翻页的图片切换效果代码分享
2015/09/08 Javascript
jQuery遍历DOM元素与节点方法详解
2016/04/14 Javascript
jQuery多个版本和其他js库冲突的解决方法
2016/08/11 Javascript
js禁止Backspace键使浏览器后退的实现方法
2017/09/01 Javascript
详解vuex 渐进式教程实例代码
2018/11/27 Javascript
jQuery实现动态添加和删除input框代码实例
2019/03/29 jQuery
js实现上传图片并显示图片名称
2019/12/18 Javascript
python 将字符串转换成字典dict
2013/03/24 Python
python重试装饰器示例
2014/02/11 Python
python 3.5下xadmin的使用及修复源码bug
2017/05/10 Python
详解python基础之while循环及if判断
2017/08/24 Python
python批量实现Word文件转换为PDF文件
2018/03/15 Python
解决pycharm工程启动卡住没反应的问题
2019/01/19 Python
Python eval的常见错误封装及利用原理详解
2019/03/26 Python
Django实现后台上传并显示图片功能
2020/05/29 Python
python能自学吗
2020/06/18 Python
linux centos 7.x 安装 python3.x 替换 python2.x的过程解析
2020/12/14 Python
canvas绘制太极图的实现示例
2020/04/29 HTML / CSS
欧洲高端品牌直销店:Fashionesta
2016/08/31 全球购物
Meli Melo官网:名媛们钟爱的英国奢侈手包品牌
2017/04/17 全球购物
美国肌肉和力量商店:Muscle & Strength
2019/06/22 全球购物
教师考察材料范文
2014/06/03 职场文书
出生证明格式
2015/06/15 职场文书
2015小学新教师个人工作总结
2015/10/14 职场文书
资产移交协议书
2016/03/24 职场文书
小程序实现悬浮按钮的全过程记录
2021/10/16 HTML / CSS
Hive HQL支持2种查询语句风格
2022/06/25 数据库
MySQL控制流函数(-if ,elseif,else,case...when)
2022/07/07 MySQL