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: ".@filesize($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);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>