PHP下载给我空pdf

时间:2014-09-26 13:28:47

标签: php pdf download

$file = "http://www.abax.se/content/download/137/862/file/example.pdf";
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
flush();
readfile($file);

这是我正在运行的代码,我的想法,任何解决方案?

1 个答案:

答案 0 :(得分:1)

删除header('Content-Length: ' . filesize($file));

这是什么打破了你的输出。

filesize()需要本地文件,而不是网址。

工作代码:

<?php
$file = "http://www.abax.se/content/download/137/862/file/example.pdf";
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
flush();
readfile($file);
?>