Skip to content

Instantly share code, notes, and snippets.

@abbotto
Created August 16, 2013 12:55
Show Gist options
  • Save abbotto/6249641 to your computer and use it in GitHub Desktop.
Save abbotto/6249641 to your computer and use it in GitHub Desktop.
A function that forces a file to download.
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