读取文件夹的子目录下的文件

直接上代码:

function read_all ($dir){
    $str = explode('/',$dir);
    unset($str[0]);
    unset($str[1]);
    $string = implode('/', $str);
    if(!is_dir($dir)) {
        echo "文件读取失败!";die;
    }

    $handle = opendir($dir);
    if($handle){
        $files = [];
        while(($file = readdir($handle)) !== false) {
            if ($file != ".." && $file != ".") {
                $path =  $string.'/'.$file;
                if (is_dir($dir . "/" . $file)) {
                    $files = array_merge($files,read_all($dir . "/" . $file));
                } else {
                    $files[] = $path;
                }
            }
        }
        closedir($handle);
        return $files;
    }else{
        return false;
    }
}

 

以上就是这次的全部内容!

posted @ 2018-08-27 14:48  静小妞  阅读(169)  评论(0编辑  收藏  举报