问题描述
在 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 的新手,我不明白这个问题。请帮帮我。
解决方法
我知道我的问题,我的表格错误,我以错误的方式传递文件。
现在,我的问题是通过使用这个来解决的,
<form action="{{route('download',$file->files)}} " method="get">
@csrf
<button type="submit" class="btn border-none btn-sm btn-primary">Download</button>
</form>