TP使用unlink刪除文件報錯:Resource temporarily unavailable

                                    TP使用unlink刪除文件報錯:Resource temporarily unavailable

一、上傳Excel文件報錯

    Error filtering template: Warning: unlink(E:....\MyFile.xls): Resource temporarily unavailable

二、代碼如下

//獲取上傳Excel文件的數據
    public function getExcelData($file){
        //文件格式校驗
        $info = $file->validate(['ext' => 'xls,xlsx'])->move('uploads');
        if (!$info){
            throw new Exception($file->getError());
        }

        //獲取上傳文件的路徑
        $path = str_replace('\\', '/', $info->getRealPath());

        //根據路徑獲取Excel表格的數據
        $data = Excel::getData($path);
        if(empty($data)){
            throw new Exception('無數據');
        }

        //unset($info); //釋放 $info 變量即可
        unlink($path);  //根據路徑刪除上傳的文件
        return $data;
    }

三、修改

    在 unlink($path); 前加上 unset($info); 即可

    即打開註釋: //unset($info); //釋放 $info 變量即可

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章