PHP遍歷目錄文件

public function read_all_dir($dir ='')
    {
        $result = array();
//      $dir = "../uploads/";
        if (is_dir($dir))
        {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                    if ($file != '.' && $file != '..'){
                        $cur_path = $dir . DIRECTORY_SEPARATOR . $file;
                        $cur_path = iconv("gb2312","UTF-8", $cur_path);//存在中文轉碼
                        if (is_dir($cur_path )) {//判斷是否爲目錄,遞歸讀取文件
                            $result['dir'][$cur_path] = $this->read_all_dir($cur_path );
                        }else{
                            $result['file'][] = $cur_path;
                        }
                    }
                }
                closedir($dh);
            }
        }
        return $result;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章