Created
August 16, 2013 12:55
-
-
Save abbotto/6249641 to your computer and use it in GitHub Desktop.
A function that forces a file to download.
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
function file_force_dl($_path) { | |
$mime = 'application/force-download'; | |
header('Pragma: public'); // required | |
header('Expires: 0'); // no cache | |
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); | |
header('Cache-Control: private',false); | |
header('Content-Type: '.$mime); | |
header('Content-Disposition: attachment; filename="'.basename($_path).'"'); | |
header('Content-Transfer-Encoding: binary'); | |
header('Connection: close'); | |
readfile($_path); // push it out | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment