我在下面有代碼,而不是保存文件,而是將臨時文件保存在適當?shù)奈恢么apublic function upload(Request $request){ //validate the file if (!$request->hasFile('file_to_import')) { return new JsonResponse([ 'status' => 'fail', 'message' => trans('json.needSelectFile'), ]); } $file = $request->file('file_to_import'); if (strtolower($file->getClientOriginalExtension()) != 'csv') { return new JsonResponse([ 'status' => 'fail', 'message' => trans('json.needValidCSV'), ]); } $disk = Storage::disk('local'); if (!$disk->exists('feeds/translations')) { $disk->makeDirectory('feeds/translations'); } $uploaded_date = now(); $name_without_extension = str_replace('.' . $file->getClientOriginalExtension(), '', $file->getClientOriginalName()); $new_filename = $name_without_extension . ' - ' . $uploaded_date . '.' . $file->getClientOriginalExtension(); $location = storage_path('app/feeds/translations/', $new_filename); $file->move($location); return new JsonResponse([ 'status' => 'success', 'filename' => $new_filename, ]);}file i uploadedwhat saved in my app location我需要的是保存真實文件translator_translations - 2019-04-15 05:52:50.csv而不是tmp文件。任何想法?
2 回答

UYOU
TA貢獻1878條經(jīng)驗 獲得超4個贊
您需要將文件名傳遞給move()
函數(shù),而不要傳遞給其他任何函數(shù),否則它將采用臨時名稱。
$file->move($destinationPath,$filename);
注意事項:
您應(yīng)該使用正確的文件名。文件名不應(yīng)包含任何特殊字符,例如空格,逗號和冒號(:)。
- 2 回答
- 0 關(guān)注
- 330 瀏覽
添加回答
舉報
0/150
提交
取消