如何使PDF文件在HTML鏈接中可下載?我在我的網(wǎng)頁上給出一個pdf文件的鏈接供下載,如下所示<a href="myfile.pdf">Download Brochure</a>問題是當(dāng)用戶單擊此鏈接時如果用戶已安裝AdobeAcrobat,則會在AdobeReader的同一瀏覽器窗口中打開該文件。如果AdobeAcrobat未安裝,則彈出用戶以下載該文件。但我希望它總是彈出到用戶下載,無論是否安裝了“Adobeacrobat”。請告訴我怎么做?
3 回答

茅侃侃
TA貢獻(xiàn)1842條經(jīng)驗 獲得超22個贊
<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 關(guān)注
- 342 瀏覽
添加回答
舉報
0/150
提交
取消