Download pdf file from href link

I am working on wordpress. I am making a meta box for PDF upload, PDF upload successfully. Now I am calling the meta value in the href link to download the pdf file. But the problem is that it can open the file but not download. For this, I am looking for a code that

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

      

$ event_flyer is used to access the meta value.

but it doesn't work for a specific href, it just works for the whole page on refresh.

+3


source to share


3 answers


If you want your PDF to be downloaded by anyone who can view your site simply by clicking on the links, you can use an attribute download

(for tags) that lets you specify the associated resource:



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

+4


source


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



+2


source


Need more code, check this:

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

0


source