Force Download in PHP

This script works in all browsers, including Internet Explorer! 🙂

if (strstr($_SERVER['HTTP_USER_AGENT'],"MSIE")) {
  header("Pragma: public");
  header("Expires: 0");
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  header("Cache-Control: private",false);
  header("Content-Type: application-download");
  header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
  header("Content-Transfer-Encoding: binary");
  header("Content-Length: "[email protected]($ab_file));
  set_time_limit(0);
} else {
  header("Content-type: application-download");
  header("Content-Length: ".filesize($ab_file));
  header("Content-Disposition attachment; filename=".$filename);
}
readfile($ab_file);

Tags:

Leave a Reply

Your email address will not be published.