Home > php教程 > PHP源码 > 递归遍历目录 及 更改目录权限

递归遍历目录 及 更改目录权限

PHP中文网
Release: 2016-05-25 17:12:48
Original
1405 people have browsed it

php代码

<?php

/**
 *      [webod] (C)2010-2099 Haowei Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
**/

//$dir ->目录 $chmod->权限 如:755

function recurDir($dir,$chmod=&#39;&#39;) {
	if(is_dir($dir)) {
		if($handle = opendir($dir)) {
			while(false !== ($file = readdir($handle))) {
				if(is_dir($dir.&#39;/&#39;.$file)) {
					if($file != &#39;.&#39; && $file != &#39;..&#39;) {
						$path = $dir.&#39;/&#39;.$file;
						$chmod ? chmod($path,$chmod) : FALSE;
						echo $path.&#39;<p>&#39;;
						recurDir($path);
					}
				}else{
					$path = $dir.&#39;/&#39;.$file;
					$chmod ? chmod($path,$chmod) : FALSE;
					echo $path.&#39;<p>&#39;;
				}
			}
		}
		closedir($handle);
	}
}

recurDir($_SERVER[&#39;DOCUMENT_ROOT&#39;],777);
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template