php 遍历目录以及子目录

源码如下:
<?php 
$dir = "c:/wamp/www/test/";  //目录名称必须是这种格式
$space="";
function fun1($dir,$space="") {
    if(is_dir($dir) && $handle = opendir($dir)){
        $space .= "&nbsp;&nbsp;&nbsp;&nbsp;";
        while(false!== ($file = readdir($handle))){
            if($file=="." || $file=="..") continue;
            if(is_dir($dir.$file.'/')){
                echo "$space|-$file<br>";
                fun1($dir.$file.'/',$space);
            }else
            echo "$space|-$file<br>";
        }
        closedir($handle);
    }else{
        echo "This have a error!";
    }
}
fun1($dir);
?>
遍历效果如下:
 |-1.php
    |-2.php
    |-2010-05-22_101859.jpg
    |-321.html
    |-ci
        |-.htaccess
        |-index.php
        |-system
27
Feb 2008
AUTHOR WiFeng
CATEGORY Web
COMMENTS No Comments

添加新评论 »

   点击刷新验证码