Laravel 5 Force下载PDF文件 [英] Laravel 5 Force Download a pdf File

查看:550
本文介绍了Laravel 5 Force下载PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已编辑

i想要强制下载laravel中的pdf文件5. laravel 4中的
我使用以下代码:

Edited
i want to Force Download a pdf File in laravel 5. in laravel 4 i used the following code:

        $file= public_path(). "/site-docs/cv.pdf";
    $headers = array(
        'Content-Type: application/pdf',
        'Content-Disposition:attachment; filename="cv.pdf"',
        'Content-Transfer-Encoding:binary',
        'Content-Length:'.filesize($file),
    );
    return \Response::download($file,"Ahmed Badawy - CV.pdf", $headers);

但在laravel 5中无效。出现此错误:

but in laravel 5 that doesn't work.it comes out with this error:

Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)

我也试过这个:

return response()->download($file);

同样的错误apeared ...
我该如何强制下载laravel 5 。

same error apeared... what can i do to force a download in laravel 5.

这是服务器的事情。不管怎么说,还是要谢谢你。
你只需启用此扩展名:php.ini文件中的php_fileinfo.dll。
然后重新启动服务器。

it was a server thing. thanks any way. you just enable this extension: php_fileinfo.dll in the php.ini file. then restart the server.

推荐答案

删除标题,它们不是必需的。在L5中,你可以做到

Remove the headers, they're not necessary. In L5, you can do

return response()->download($file, "Ahmed Badawy - CV.pdf");

阅读文档

这篇关于Laravel 5 Force下载PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆