jeck猫
而不是链接到.PDF文件,而是执行以下操作Download my eBook它输出一个自定义的标题,打开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添加到值中。