转自 RIPS ---- [./lib/filer.php] -----sourceforge.net/projects/rips-scanner/
// 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 subdirectories
function 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
";
}
?>