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设计模式 Factory(工厂模式)
Jun 26 PHP
php数据类型判断函数有哪些
Sep 23 PHP
php Calender(日历)代码分享
Jan 03 PHP
wamp安装后自定义配置的方法
Aug 23 PHP
PHP模块memcached使用指南
Dec 08 PHP
php动态变量定义及使用
Jun 10 PHP
PHP基于phpqrcode生成带LOGO图像的二维码实例
Jul 10 PHP
php验证码生成代码
Nov 11 PHP
PHP面向对象程序设计实例分析
Jan 26 PHP
PHP 返回13位时间戳的实现代码
May 13 PHP
CI框架常用方法小结
May 17 PHP
php判断用户是否关注微信公众号
Jul 22 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 智能404跳转代码,适合换域名没改变目录的网站
2010/06/04 PHP
PHP实现单例模式最安全的做法
2014/06/13 PHP
curl和libcurl的区别简介
2015/07/01 PHP
jQuery Autocomplete自动完成插件
2010/07/17 Javascript
jQuery中triggerHandler()方法用法实例
2015/01/19 Javascript
JS实现在状态栏显示打字效果完整实例
2015/11/02 Javascript
ES6的新特性概览
2016/03/10 Javascript
利用js的闭包原理做对象封装及调用方法
2017/04/07 Javascript
JS SetInterval 代码实现页面轮询
2017/08/11 Javascript
详解从新建vue项目到引入组件Element的方法
2017/08/29 Javascript
分享ES6的7个实用技巧
2018/01/18 Javascript
angular5 httpclient的示例实战
2018/03/12 Javascript
AngularJS实现与后台服务器进行交互的示例讲解
2018/08/13 Javascript
vue2.0自定义指令示例代码详解
2019/04/25 Javascript
[02:39]我与DAC之Newbee.Moogy:从论坛到TI
2018/03/26 DOTA
[13:25]VP vs VICI (BO3)
2018/06/07 DOTA
Python 调用DLL操作抄表机
2009/01/12 Python
python使用pil生成缩略图的方法
2015/03/26 Python
python实现发送和获取手机短信验证码
2016/01/15 Python
Python中time模块和datetime模块的用法示例
2016/02/28 Python
python selenium firefox使用详解
2019/02/26 Python
Python绘图实现显示中文
2019/12/04 Python
Python requests模块session代码实例
2020/04/14 Python
如何通过python实现IOU计算代码实例
2020/11/02 Python
纯css3实现的鼠标悬停动画按钮
2014/12/23 HTML / CSS
乌克兰香水和化妆品网站:Notino.ua
2018/03/26 全球购物
YBF Beauty官网:美丽挚友,美国知名彩妆品牌
2020/11/22 全球购物
金鑫耀Java笔试题
2014/09/06 面试题
优秀团员个人的自我评价
2013/10/02 职场文书
三项教育活动实施方案
2014/03/30 职场文书
庆六一活动总结
2014/08/29 职场文书
关于拾金不昧的感谢信
2015/01/21 职场文书
5.12护士节活动总结
2015/02/10 职场文书
教师个人自我评价
2015/03/04 职场文书
地道战观后感2000字
2015/06/04 职场文书
Python Flask实现进度条
2022/05/11 Python