March 7, 2013

Force Download File with php finfo

PHP: Hypertext Preprocessor

Force Download File with php finfo

$file_info = new finfo(FILEINFO_MIME);
$type = $file_info->buffer(file_get_contents($zip_file));
header("Pragma: public");
header("Expires: 0");
header("Pragma: no-cache");
header("Charset: null");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-disposition: attachment; filename=' . str_replace(' ','-', file_parts($zip_file,'name')));
header("Content-Type: $type");
header("Content-Transfer-Encoding: binary");
header('Content-Length: ' . filesize($zip_file));
@readfile($zip_file);
exit(0);

Its a revision to Download file problem due to version incompatibility of IE & Adobe Reader

Dependency function file_parts

Last updated: March 19, 2014