如何使PDF文件在HTML链接中可下载?我在我的网页上给出一个pdf文件的链接供下载,如下所示<a href="myfile.pdf">Download Brochure</a>问题是当用户单击此链接时如果用户已安装AdobeAcrobat,则会在AdobeReader的同一浏览器窗口中打开该文件。如果AdobeAcrobat未安装,则弹出用户以下载该文件。但我希望它总是弹出到用户下载,无论是否安装了“Adobeacrobat”。请告诉我怎么做?
3 回答
jeck猫
TA贡献1909条经验 获得超7个赞
<a href="pdf_server.php?file=pdffilename">Download my eBook</a>
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);
- 3 回答
- 0 关注
- 3839 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消