尝试这个。
public function getDownload(){ //PDF file is stored under project/public/download/info.pdf $file= public_path(). "/download/info.pdf"; $headers = array( 'Content-Type: application/pdf', ); return Response::download($file, 'filename.pdf', $headers);}"./download/info.pdf"将无法正常工作,因为您必须提供完整的物理路径。
更新20/05/2016
Laravel 5、5.1、5.2或5. *用户可以使用以下方法代替
ResponseFacade。但是,我先前的答案对Laravel
4或5都适用。(将
$header数组结构更改为关联数组
=>-删除“ Content-Type”后的冒号-
如果我们不执行这些更改,则将以错误的方式添加标头:标头名称将从0,1,…开始。
$headers = [ 'Content-Type' => 'application/pdf',];return response()->download($file, 'filename.pdf', $headers);



