Laravel 5.5下载

时间:2018-04-14 09:21:03

标签: laravel laravel-5 download controller

我遇到强行下载问题:

在我的页面中,我有一行代码:

@php
  $pg = "/downloadWirebird/".$mag->PDF;
@endphp
<a href="{{ $pg }}">@fa('download')</a>&nbsp;&nbsp

在我的web.php文件中,我有:

Route::get('/downloadWirebird/{file}','DownloadsController@downloadWirebird');

然后我的控制器中有以下方法:

public function downloadWirebird($file)
 {
 $file_path = public_path('Wirebird/').$file;
 return response()->download($file_path);
 }

但是我得到了回复

  

Symfony \ Component \ HttpFoundation \ File \ Exception \ FileNotFoundException   文件&#34; /home/sites/sthelena.uk.net/public_html/work/public/Wirebird"不存在

似乎忽略了文件本身。

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

有点摆弄,我已经对它进行了分类。

视图代码是

  @php
    $pg = "/downloadWirebird/".$mag->PDF;
  @endphp
  <a href="{{ $pg }}">@fa('download')</a>&nbsp;&nbsp

路线是

Route::get('/downloadWirebird/{file}','DownloadsController@downloadWirebird');

,控制器是

public function downloadWirebird($file)
 {
  $file_path = public_path('Wirebird/').$file;
  return response()->download($file_path);
 }
相关问题