Zahra Aleem Zahra Aleem - 4 months ago 17
PHP Question

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.

Answer

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