不要链接到.PDF文件,而是执行类似操作
<a href="pdf_server.php?file=pdffilename">Download my eBook</a>
输出自定义标题,打开PDF(二进制保险箱)并将数据打印到用户的浏览器,然后他们可以选择保存PDF,尽管他们的浏览器设置。pdf_server.php应如下所示:
header("Content-Type: application/octet-stream");
$file = $_GET["file"] .".pdf";
header("Content-Disposition: attachment; filename=" . urlencode($file));
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp);
PS:并且显然对“file”变量运行一些健全性检查,以防止人们窃取您的文件,例如不接受文件扩展名,拒绝斜杠,向值添加.pdf