我无法在 Laravel 中下载我上传的文件显示文件不存在

问题描述

在 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>

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...