readfile函数用于PDF下载问题

时间:2013-03-01 14:31:34

标签: php

我知道这个问题已被提出,但提供的解决方案对我不起作用。我可以下载PDF,但Adobe Reader告诉我它已损坏或解码不正确。有没有人有替代解决方案或可能的解决方案?

$path = "http://www.laerdalmail.com/discoversimulation/downloads/needs_assessment_form.pdf";
header('Content-Type: application/pdf'); 
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=needs_assessment_form.pdf"); 
readfile($path); 
exit; 

1 个答案:

答案 0 :(得分:0)

readfile应该被赋予文件系统路径,而不是URL。像这样的东西:

$path = '/websitefolder/discoversimulation/downloads/needs_assessment_form.pdff';
// or
$parh = 'c:\something\needs_assessment_form.pdff';

尝试添加内容长度:

header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($path));