//First, see if the file exists
if (!is_file($file)) { die("<b>404 File not found!</b>"); }
//Gather relevent info about file
$len = filesize($file);
$filename = basename($file);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
//This will set the Content-Type to the appropriate setting for the file
switch( $file_extension ) {
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/x-zip-compressed"; break;
case "rar": $ctype="application/x-rar"; break;
default: $ctype="application/force-download";
}
//Use the switch-generated Content-Type
header("Content-Type: $ctype");
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
# workaround for IE filename bug with multiple periods / multiple dots in filename
# that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe
$iefilename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1);
header("Content-Disposition: attachment; filename=\"$iefilename\"");
//header("Content-Range: $from-$to fsize"); 加上压缩包头信息不正确
//header("Content-Length: $content_size"); 加上压缩包头信息不正确
} else {
header("Content-Disposition: attachment; filename=\"$filename\"");
//header("Content-Range: $from-$to fsize"); 加上压缩包头信息不正确
//header("Content-Length: $content_size"); 加上压缩包头信息不正确
}
header("Accept-Ranges: bytes");
//header('Expires: '.gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y"))).' GMT');
$size=filesize($file);
//open the file
$fp=fopen("$file","rb");
/ ek to start of missing part
fseek($fp,$range);
//start buffered download
while(!feof($fp)){
//reset time limit for big files
set_time_limit(0);
print(fread($fp,1024*8));
//flush(); 这个是多余的函数,加上会使压缩包下载不完整
//ob_flush(); 这个也是多余的函数,加上会使压缩包下载不完整
}
fclose($fp);
exit;
}
?>