我正在尝试在单击链接时强制下载PDF但我仍然从readfile接收标题警告和奇怪的字符。
<a>
代码:
<p>The pdf file is large and can take a minute to download.
You can <a href="/icisherbrooke/downloadAnnuaire.php">click here to download the pdf.</a></p>
download.php文件:
<?php
$fullpath = 'annuaire_2013-14_optimized3.pdf';
if(file_exists($fullpath)){
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="annuaire_2013-14_optimized3.pdf"');
readfile($fullpath);
exit();
}
?>
当我用echo "test"
替换标题和readfile时,它可以正常工作。
我没有下载提示,而是重定向到download.php。以下是download.php的结果的一部分:
Warning: Cannot modify header information - headers already sent by (output started at /home/kanope/vhost_file/info-rapide.com/icisherbrooke/downloadAnnuaire.php:1) in /home/kanope/vhost_file/info-rapide.com/icisherbrooke/downloadAnnuaire.php on line 8
%PDF-1.6 %���� 1561 0 obj <> endobj 1575 0 obj <>/Filter/FlateDecode/ID[<0EC5F18608359D479CC3DB0FF72E23C8><997B135B48FBE541BDE876EE8BECFD9D>]/Index[1561 20]/Info 1560 0 R/Length 95/Prev 216592620/
答案 0 :(得分:1)
如错误所示,第1行有一些输出。它通常是空格。如果您没有看到任何空格,请检查BOM。 :)