我正在使用wordpress。我製作了一個上傳pdf文件的meta字段,併成功上傳了pdf文件。現在,我叫meta值在HREF鏈接,下載PDF file.But的問題是,它可以打開該文件,但不download.For這個我搜索代碼,從href鏈接下載pdf文件
<?php
header("Content-Disposition: attachment; filename=$event_flyer");
?>
$ event_flyer用於訪問元值。
但它沒有爲特定的href工作,它只是在整個頁面上刷新。其實
header("Content-disposition: attachment; filename=$pathtopdf"); header("Content-type: application/octet-stream"); readfile($pathtopdf);
感謝它的工作 –
請記住,下載屬性的瀏覽器兼容性還不是很好:[caniuse.com/#feat=download] (http://caniuse.com/#feat=download) – Theunis