Last active
January 3, 2016 17:29
-
-
Save justmytwospence/8495937 to your computer and use it in GitHub Desktop.
This PHP function will initiate a direct download of a file (pdf, etc.). MIME type on line 5 will also need to be changed if not PDF (eg "application/xml"). Now just create a hyperlink directly to this php script.
This file contains 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
<?php | |
$actual_file_name = "path/to/foo.pdf"; | |
$saved_file_name = "foo-bar.pdf" | |
header("Content-Type: application/pdf"); | |
header("Content-Disposition: attachment; filename=$saved_file_name"); | |
header("Content-Length: " . filesize($actual_file_name)); | |
readfile($actual_file_name); | |
exit; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment