Return to Snippet

Revision: 60106
at October 20, 2012 10:51 by o0110o


Initial Code
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();
}

Initial URL


Initial Description
This function will force a file to be downloaded. It accepts $_path as a parameter.

Initial Title
A function that forces a file to download.

Initial Tags
php, download, function

Initial Language
PHP