PHP遍历某个目录下的所有文件和子文件夹的实现代码_PHP教程
时间:2021-07-01 10:21:17
帮助过:3人阅读
代码如下:
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;
}
?>
http://www.bkjia.com/PHPjc/327951.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327951.htmlTechArticle 代码如下:?php function read_all_dir ( $dir ) { $result = array(); $handle = opendir($dir); if ( $handle ) { while ( ( $file = readdir ( $handle ) ) !== false ) {...