【问题标题】:I can't download my uploaded file in Laravel. It show file does not exist我无法在 Laravel 中下载我上传的文件。它显示文件不存在
【发布时间】: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


    【解决方案1】:

    我遇到了问题,我的表单错误,我传递文件的方式错误。

    现在,我的问题通过这个解决了,

    <form action="{{route('download', $file->files)}} " method="get">
        @csrf
      <button type="submit" class="btn border-none btn-sm btn-primary">Download</button> 
       </form>
    

    【讨论】:

      猜你喜欢
      • 2020-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-18
      • 2014-11-14
      相关资源
      最近更新 更多