Possible Duplicate:
open download dialog with php
I have a link in my page say, <a href='test.pdf'>(Test.pdf)</a>
.
When I click on that link, download dialogue box should open to download that file.
Can anyone help me in implementing this in PHP?
thanks
$filename = 'Test.pdf'; // of course find the exact filename....
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false); // required for certain browsers
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="'. basename($filename) . '";');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($filename));
readfile($filename);
exit;
Name the above file as download.php
HTML:
<a href="download.php">Test.pdf</a>
That should do it.
<a href="test.pdf">test.pdf</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