Advertisement
Force a download on the browser
-
Here’s a piece of code which will force download a pdf instead of showing it inline in the browser.
< ?php
header('Pragma: public');
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Content-Transfer-Encoding: none');
header('Content-Type: application/pdf; name="$path->pdfname"');
header('Content-Disposition: inline; filename="$path->pdfname"');
readfile($path->pdfpath);
?>This code can be modifed to allow other file formats to be downloaded by just changing the mime type in the Content-Type: tag to the correct type for the file you wish to send.
Here’s a quick reference to frequently used mime-types:
http://www.utoronto.ca/webdocs/HTMLdocs/Book/Book-3ed/appb/mimetype.html
Advertisement
-
Jon B
-
vinu
