Skip to content

Instantly share code, notes, and snippets.

@arturocr
Created May 9, 2012 19:36
Show Gist options
  • Select an option

  • Save arturocr/2648245 to your computer and use it in GitHub Desktop.

Select an option

Save arturocr/2648245 to your computer and use it in GitHub Desktop.
Force Download in PHP
<?php
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment