erdy
July 26, 2010, 9:11am
1
Hi,
I need to create a link that will download a PDF file to the viewers hardrive instead of opening it in the browser?
A simple link like this:
<a href=“http://www.mysite/pdfs/pdf_file.pdf ”>Download Brochure</a>
…just opens it in the browser but this is for a company brochure and I need it to go on to the viewers hardrive.
Any clues, or should I have posted this Thread in the Javascript catagory.
Thanks
Erdy
The only way to do it without changing the headers usung a server side language is to place instructions in your page telling your visitor to right click and select to download from the menu.
If you have PHP on your server, you could use something like this:
<?php
$filename = "brochure.pdf";
header("Content-Length: " . filesize($filename));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=brochure.pdf');
readfile($filename);
?>
Name this file brochure.php.
Then use a link to to brochure.php, and then php will start the download process in the browser.