【发布时间】:2021-05-04 05:11:44
【问题描述】:
在 Laravel 中, 我在存储中成功上传了文件,并将存储与公共链接。我上传的目录是这样的,
This is my download directory map
这是我的下载按钮代码,
<form action="{{route('download', $file->id)}} " method="get">
@csrf
<button type="submit" class="btn border-none btn-sm btn-primary">Download</button>
</form>
这是我为此设置的路线,
//Download uploaded file
Route::get('/download/{file}', [UploadUserFileController::class, 'downloadfile'])->name('download')->middleware('auth');
这是我的控制器代码,
// Download requested file
public function downloadfile($id){
$filelink = File::find($id);
// return Storage::disk('public')->download('./storage/files/'.$filelink->files);
// return Storage::download('./files/'.$filelink->files);
return response()->download('/storage/files/'.$filelink->files, $filelink->files);
}
但是当我点击下载按钮后,它会显示这个错误,
文件“/storage/files/Demand.pdf”不存在
我是 Laravel 的新手,我不明白这个问题。请帮帮我。
【问题讨论】:
标签: database laravel file-upload file-not-found not-exists