<?php
//遍历当前目录下所有文件的和目录,并以树装形式显示
//1.打开目录句柄,获取句柄资源
//2.读取句柄资源,并显示当前和子目录下的(目录和文件名称)
function getDirFile($path){
if($file_handler=opendir($path)){
while(false !== ($file=readdir($file_handler))){
if($file!="." && $file!=".."){
if(is_dir("$path/$file")){
if(substr_count("$path/$file","/")>1){
$count=str_repeat("    ",substr_count("$path/$file","/"));
echo $count.$file;
}else{
echo $file;
}
echo "<br/>";
getDirFile("$path/$file");
}else{
if(substr_count("$path/$file","/")>1){
$count=str_repeat("    ",substr_count("$path/$file","/"));
echo $count.$file;
}else{
echo $file;
}
echo "<br/>";
}
}
}
}
}
$path="D:\software\wamp\www\messageboards";
getDirFile($path);
?>
转载于:https://blog.51cto.com/caozm/1301171