<?php
function display_dir($dir, $deep = 0)
{
static $file_list = array();
$dp = opendir($dir);
while($temp = readdir($dp))
{
if($temp == '.' || $temp == '..'){
continue;
}
if(is_dir($dir.'/'.$temp)){
$file_info['filename'] = $temp;
$file_info['deep'] = $deep;
$file_info['type'] = 'dir';
$file_list[] = $file_info;
// echo "<b style='color:blue;'>".str_repeat(" ", $deep * 4).$temp."</b><br />";
display_dir($dir.'/'.$temp, $deep + 1);
}
else{
$file_info['filename'] = $temp;
$file_info['deep'] = $deep;
$file_info['type'] = 'file';
$file_list[] = $file_info;
// echo "<b style='color:pink;'>".str_repeat(' ', $deep * 4).$temp."</b><br />";
}
}
return $file_list;
}
$list = display_dir("D:\WWW\de\uploads");
foreach($list as $key => $value)
{
if($value['type'] == 'dir'){
echo "<b style='color:blue'>".str_repeat(' ', $value['deep'] * 4).$value['filename']."</b><br />";
}
else if($value['type'] == 'file'){
echo "<b style='color:pink'>".str_repeat(' ', $value['deep'] * 4).$value['filename']."</b><br />";
}
}
?>
递归读取目录
最新推荐文章于 2022-03-12 10:47:12 发布