PHP遍历某个目录下的所有文件和子文件夹的实现代码_php技巧
时间:2021-07-01 10:21:17
帮助过:32人阅读
代码如下:
function read_all_dir ( $dir )
{
$result = array();
$handle = opendir($dir);
if ( $handle )
{
while ( ( $file = readdir ( $handle ) ) !== false )
{
if ( $file != '.' && $file != '..')
{
$cur_path = $dir . DIRECTORY_SEPARATOR . $file;
if ( is_dir ( $cur_path ) )
{
$result['dir'][$cur_path] = read_all_dir ( $cur_path );
}
else
{
$result['file'][] = $cur_path;
}
}
}
closedir($handle);
}
return $result;
}
?>