0

我试图在单击链接时强制下载 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>

下载.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();
}

?>

当我用 a 替换标题和 readfile 时echo "test",它​​可以工作。

我被重定向到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/

4

1 回答 1

1

如错误所示,第 1 行有一些输出。它通常是空格。如果您没有看到任何空白,请检查 BOM。:)

于 2013-06-18T17:21:37.970 回答