知道一个目录的路径,使用递归获取该目录下的所有文件:
function rDir($filepath)
{
$result = array();//获取的结果保存在这个数组中
if(is_dir($filepath))
{
$re = opendir($filepath);
while (($file=readdir($re)) != false)
{
if ($file != '.' && $file != '..')
{
$curpath = $filepath.'/'.$file;
if (is_dir($curpath))
{
$func = __FUNCTION__;
$res = $func($curpath);
$result[$file]=$res;
}
else
{
$result[]=$file;
}
}
}
closedir($re);
return $result;
}
else if(is_file($filepath))
{
return '这个是文件,不是目录';
}
else
{
return '这是什么东西?';
}
}