我在下面有代碼,而不是保存文件,而是將臨時(shí)文件保存在適當(dāng)?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我需要的是保存真實(shí)文件translator_translations - 2019-04-15 05:52:50.csv而不是tmp文件。任何想法?
Laravel改為存儲(chǔ)臨時(shí)文件
桃花長(zhǎng)相依
2021-04-06 17:15:49