【问题标题】:Call to undefined method Symfony\Component\HttpFoundation\BinaryFileResponse::header() during downloading file在下载文件期间调用未定义的方法 Symfony\Component\HttpFoundation\BinaryFileResponse::header()
【发布时间】:2019-07-31 14:55:55
【问题描述】:

我想下载一个文件,但每当我尝试下载它时,它都会显示此错误:

调用未定义的方法 Symfony\Component\HttpFoundation\BinaryFileResponse::header()

@if($document->file)
    <td>
        <a href="{{route('file.download',$document->file)}}"><button class="btn btn-xs btn-outline-warning">{{$document->file}}</button></a> 
    </td>
@endif

路线:

Route::get('/employee/file/download/{file}','ErpEmployeeController@fileDownload')->name('file.download');

控制器:

public function fileDownload($file)
{
    $files = public_path() . "/uploads/file/" . $file;

    return response()->file($files);
}

【问题讨论】:

  • 如果你想下载你应该使用response()-&gt;download($files);

标签: laravel


【解决方案1】:

如果你想下载,你应该使用download()函数:

response()->download($files);

【讨论】:

  • 如果可行,请考虑接受并支持答案
  • 这不是问题。问题是我必须编辑这个 Symfony\Component\HttpFoundation\BinaryFileResponse::header() 函数。答案在这里:stackoverflow.com/questions/47429829/…
  • 您发布的问题解释说,仅当覆盖响应标头的用户中间件处于活动状态时才会出现下载错误,您是否有某种中间件处于活动状态?
猜你喜欢
  • 1970-01-01
  • 2017-09-21
  • 2018-05-20
  • 1970-01-01
  • 1970-01-01
  • 2018-02-16
  • 1970-01-01
  • 1970-01-01
  • 2018-10-23
相关资源
最近更新 更多