2
votes

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.

3

3 Answers

3
votes

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

1
votes

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.

0
votes

You need more code, check this:

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