Forum Moderators: coopster
//set m-type
$mtype = '';
if($allowed_ext[$fext] == ''){
// mime type is not set, get from server settings
$mtype = mime_content_type($file_path);
}
else{
$mtype = $allowed_ext[$fext];
}
if ($mtype == '') {
$mtype = "application/force-download";
}
//echo "\$mtype : $mtype<br>"; //this prints out the correct mtype
//echo "\$fname: $fname"; //this prints out the correct file name// set headers
@ini_set('zlib.output_compression', 'Off');
header("Pragma: public");
header("Expires: 0");
header('Cache-Control: no-store, no-cache, must-revalidate');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: $mtype");
header("Content-Disposition: attachment; filename=\"$fname\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $fsize);
// download
//@readfile($file_path);
$file = @fopen($file_path,"r");
if ($file) {
while(!feof($file)) {
print(fread($file, 1024*8));
flush();
if (connection_status()!=0) {
@fclose($file);
die();
}
}
@fclose($file);
}