Last active
December 16, 2015 11:48
-
-
Save alwerner/5429504 to your computer and use it in GitHub Desktop.
Source: http://stackoverflow.com/questions/364946/how-to-make-pdf-file-downloadable-in-html-link "[...]run some sanity checks on the "file" variable to prevent people from stealing your files such as don't accept file extensions, add .pdf to the value."
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="pdf_server.php?file=pdffilename">Download my pdf</a> | |
// pdf_server.php | |
header("Content-Type: application/octet-stream"); | |
$file = $_GET["file"] .".pdf"; | |
header("Content-Disposition: attachment; filename=" . urlencode($file)); | |
header("Content-Type: application/force-download"); | |
header("Content-Type: application/octet-stream"); | |
header("Content-Type: application/download"); | |
header("Content-Description: File Transfer"); | |
header("Content-Length: " . filesize($file)); | |
flush(); // this doesn't really matter. | |
$fp = fopen($file, "r"); | |
while (!feof($fp)) | |
{ | |
echo fread($fp, 65536); | |
flush(); // this is essential for large downloads | |
} | |
fclose($fp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment