I am trying to make it so when you click "download here" a pdf file will download to the user's desktop. How should I go about doing this?
Use the Content-Disposition header.
But, please: Only do this if it is really necessary for the user to download the PDF and not open it (so that it’s just an aid for the user that he does not have to explicitly select “save file”). Don’t use it to force the user to download it although he just wants to view it.
code for a.php:
<?php
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename=file.pdf')
echo file_get_contents("file.pdf");
?>
link it in web:
<a href="a.php">Download</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With