简体   繁体   中英

Download pdf from href link issue

I am working on a wordpress. I make a meta field for upload pdf file,pdf file upload sucessfully. Now i call meta value in href link for download the pdf file.But the problem is that it can open the file but not download.For this i search a code that is

<?php  
header("Content-Disposition: attachment; filename=$event_flyer");
?>

$event_flyer is used for accessing meta value.

but its not working for specific href its just working for whole page on refresh.

If you want your pdf file to be downloadable by anyone who could browse your website just by clicking on links, then you can use the download attribute (for tags) which allows you to specify the linked resource :

Doc here : http://www.w3schools.com/tags/att_a_download.asp

Actually if you have a reader installed it will always open instead of downloading. If you have hosted your wordpress on a live server then you can try to open link on a PC where PDF reader is not installed. It will download the file instead of opening.

您需要更多代码,请检查以下内容:

header("Content-disposition: attachment; filename=$pathtopdf"); header("Content-type: application/octet-stream"); readfile($pathtopdf);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM