PHP下载pdf文件无法正常工作

时间:2015-05-25 19:02:12

标签: php downloadfile

我使用此代码下载pdf文件。下载开始但是下载完成后adobe无法打开pdf文件。

$file_url = "http://kolikokostagrejanje.​rs/step7/proracun-short.pdf";
header('Content-Type: application/pdf');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=proracun-short-skinuto.pdf");
readfile($file_url);

当前PHP版本:5.4.36

解决

问题是pdf文件没有权限777。

2 个答案:

答案 0 :(得分:1)

文件是否具有读取权限。还要检查其他文件是否出现同样的问题(如果文件已损坏)

答案 1 :(得分:0)

我的猜测是你的脚本可能包含NOTICE或WARNING,因此请尝试在脚本中禁用错误​​报告来解决问题。

error_reporting(0);

并且最好将readfile与错误抑制操作符一起使用,尤其是在执行下载任务时

@readfile($path)
相关问题