php ---- 文件遍历

来源:互联网 发布:网络销售授权证书 编辑:程序博客网 时间:2024/05/17 06:30

转自 RIPS ---- [./lib/filer.php] -----sourceforge.net/projects/rips-scanner/

<?php// filetypes you want to search        $FILETYPES = array(  // filetypes to scan                '.php','.inc','.phps','.php4','.php5',//'.html', //'.htm', //'.txt','.phtml','.tpl','.cgi');// get all php files from directory, including all subdirectoriesfunction read_recursiv($path, $scan_subdirs){$result  = array();$handle  = opendir($path);if ($handle){// readdir -- 此函数可能返回布尔值 FALSE,但也可能返回等同于 FALSE 的非布尔值。while (false !== ($file = readdir($handle))){if ($file !== '.' && $file !== '..'){$name = $path . '/' . $file;if (is_dir($name) && $scan_subdirs){$ar = read_recursiv($name, true);foreach ($ar as $value){// string substr ( string $string , int $start [, int $length ] )// strrpos   ---- 计算指定字符串在目标字符串中最后一次出现的位置// in_array  ---- if(in_array(substr($value, strrpos($value, ".")), $GLOBALS['FILETYPES'])){// Append the  filepath to the result array$result[] = $value;}}} else if (in_array(substr($name, strrpos($name, '.')), $GLOBALS['FILETYPES'])){$result[] = $name;}}}}closedir($handle);return $result;}$files = (read_recursiv("/var/www/rips/",1));foreach ($files as $file){echo $file."\n<br />";}?>



0 0
原创粉丝点击