php遍历文件夹(或文件)

<?php
function read_dir($dir){
    $arr = array();
    $arr[] = $dir;
    if (is_dir($dir)){
        $dh = opendir($dir);
        if (!$dh){
            return $arr;
        }
        while ($file = readdir($dh)){
            if ($file == '.' || $file == '..'){
                continue;
            }
            $file = $dir . '/' . $file;
            $tmp = read_dir($file);
            $arr = array_merge($arr,$tmp);
            }
        }
    return $arr;
}
?>

posted on 2012-08-02 15:52  ianarfa  阅读(170)  评论(0编辑  收藏  举报

导航