我正在嘗試storage/app使用 laravel 上傳一個檔案,我正在檢查我的檔案夾是否存在:
if(isset($request->file_job)){
$pathFolder = storage_path('app/contratos/'.$tarea->contratoTrey->serie->SERIE.'-'.$tarea->contratoTrey->N_CONTRATO.'/tareas/T-'.$tarea->ntarea);
if(!\File::exists($pathFolder)) {
\File::makeDirectory($pathFolder, 0755, true, true);
}
$filePath = 'app/contratos/'.$tarea->contratoTrey->serie->SERIE.'-'.$tarea->contratoTrey->N_CONTRATO.'/tareas/T-'.$tarea->ntarea;
\Storage::disk('local')->put($filePath, $request->file_job);
}
如果不存在,我正在構建我的結構檔案夾并將我的檔案放在這個檔案夾中。
我的問題在我的資料庫中,我插入我的檔案名,getClientOriginalName()但在這條路線上
'app/contratos/'.$tarea->contratoTrey->serie->SERIE
我的應用程式是構建一個檔案,而不是目錄,在這個目錄中我的檔案使用他的原始名稱......
我不知道我做錯了..我用這個名稱創建了一個新變數并保存......同樣的錯誤或問題......
更新
\Storage::disk('local')->putFileAs($filePath, $request->file_job, ($request->file_job)->getClientOriginalName());
感謝自述檔案并幫助我。對不起,我的英語不好
uj5u.com熱心網友回復:
問題可能是您使用的是 put 而不是 putFileAs。您可以在https://laravel.com/docs/9.x/filesystem#specifying-a-file-name中找到檔案,而不是:
\Storage::disk('local')->put($filePath, $request->file_job);
你應該:
\Storage::disk('local')->putFileAs($filePath, $request->file_job, ($request->file_job)->getClientOriginalName());
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/460831.html
