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.

Read More

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

Related posts

Leave a Reply

3 comments

  1. 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.

  2. You need more code, check this:

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