我有一个可恢复的下载 php 脚本。
它在 Apache 服务器上运行良好,但在 IIS 7(我的客户端当前使用)上运行良好
IIS的问题是:
下载文件时,同一站点的其他页面将冻结。(有时甚至显示 500 服务器错误)(Apache 服务器上的相同脚本不会出现相同的问题)
如果我关闭可恢复支持,问题就会消失(即使在下载管理器上下载也会冻结查看同一站点的所有浏览器)
这让我相信 IIS 需要一些配置?还是php.ini?
到目前为止,我对谷歌的任何帮助都将不胜感激,并且.. 是的,我可以访问 IIS 和 php.ini,是的..我已经在 IIS 上设置了最大连接时间(大文件传输需要)
这个脚本是..(任何人在这里遇到并喜欢在 IIS 上使用此脚本进行大文件传输,请阅读 --> IIS 7 上的 php >> FastCGI 超时设置<<)
$filename="test.flv";
$filepath="zekkai.flv";
//set mime
$mime_type="";
$known_mime_types=array(
"flv" => "video/x-flv",
"mp4" => "video/mp4",
"mov" => "video/quicktime",
"avi" => "video/x-msvideo",
"wmv" => " video/x-ms-wmv "
);
if($mime_type==''){
$file_extension = strtolower(substr(strrchr($filepath,"."),1));
if(array_key_exists($file_extension, $known_mime_types)){
$mime_type=$known_mime_types[$file_extension];
} else {
$mime_type="application/force-download";
};
};
header("Connection: Keep-Alive");
header("Keep-Alive: timeout=65000");
$fsize=filesize($filepath);
set_time_limit(0);
//turn off buffer
ob_end_clean();
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
header("Content-Description: File Transfer");
header("Content-type: ".$mime_type);
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Accept-Ranges: bytes');
header("Cache-control: public");
header('Pragma: public');
header("Expires: 0");
// resumable support..
if(isset($_SERVER['HTTP_RANGE'])){
// delete this part to turnoff resumable support
list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2);
list($range) = explode(",",$range,2);
list($range, $range_end) = explode("-", $range);
$range=intval($range);
if(!$range_end) {
$range_end=$fsize-1;
} else {
$range_end=intval($range_end);
}
$new_length = $range_end-$range+1;
header("HTTP/1.1 206 Partial Content");
header("Content-Length: $new_length");
header("Content-Range: bytes $range-$range_end/$fsize");
// resumable support end
} else {
$new_length=$fsize;
header("Content-Length: ".$fsize);
}
/* output the file itself */
$chunksize = 3*(1024*1024); //you may want to change this
$bytes_send = 0;
if ($Source_File = fopen($filepath, 'rb')){
if(isset($_SERVER['HTTP_RANGE'])){
fseek($Source_File, $range);
}
while(!feof($Source_File) && (!connection_aborted()) && ($bytes_send<$new_length) ) {
$buffer = fread($Source_File, $chunksize);
print($buffer); //echo($buffer); // is also possible
flush();
$bytes_send += strlen($buffer);
}
fclose($Source_File);
} else die('Error - can not open file.');
exit();