Download File PHP Function
function download($path) {
//global $_SERVER['HTTP_USER_AGENT'];
$file=basename($path);
$size = filesize($path);
header("Content-Type: application/octet-stream");
header("Content-Type: application/force-download");
header("Content-Length: $size");
// IE5.5 just downloads index.php if we don't do this
if(preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
header("Content-Disposition: filename=$file");
} else {
header("Content-Disposition: attachment; filename=$file");
}
header('Cache-Control: maxage=3600'); //Adjust maxage appropriately
header('Pragma: public');
header("Content-Transfer-Encoding: binary");
$fh = fopen($path, "r");
fpassthru($fh);
}
No comments:
Post a Comment