目录遍历

function listDirTree($dirName=null) {
    $dirName=str_replace("\","/",$dirName);
    if(empty($dirName))exit("IBFileSystem:directoryisempty.");
    if(is_dir($dirName)) {
        if($dh=opendir($dirName)) {
            $tree=array();
            while(($file=readdir($dh))!==false) {
                if($file!="."&&$file!="..") {
                    $filePath=$dirName."/".$file;
                    if(is_dir($filePath)) {
                        $tree[$filePath]=listDirTree($filePath);
                    } else {
                        $tree[]=$filePath;
                    }
                }
            }
            closedir($dh);
        } else {
            exit("IBFileSystem:cannotopendirectory$dirName.");
        }
        return$tree;
    } else {
        exit("IBFileSystem:$dirNameisnotadirectory.");
    }
}
原文地址:https://www.cnblogs.com/xuyaoxiang1991/p/3311781.html