试试这个标题,你可以用简历下载我建议使用数据库或日志文件来了解下载的文件,因为这个标题可用下载器下载部分
从下载器获取请求范围,您可以使用 fseek 读取文件范围
$Range=@$_SERVER['HTTP_RANGE'];//Range: bytes=843530240-
$Cach="";
if($Range!=""){
$Range=explode("=",$Range);
$Cach=(int)trim($Range[1]," -");
}
缓存控制器
function caching_include($file) {
$headers = $_SERVER;
// Get the modification timestamp
if(!(list(,,,,,,,,,$lastModified) = @stat($file))){
echo Error;
exit();
}
// Build our entity tag
$eTag = "ci-".dechex(crc32($file.$lastModified));
if (false and (strpos(@$headers['If-None-Match'], "$eTag")) &&(gmstrftime("%a, %d %b %Y %T %Z", $lastModified) == @$headers['If-Modified-Since'])) {
// They already have an up to date copy so tell them
header('HTTP/1.1 304 Not Modified');
header('Cache-Control: private');
header("Pragma: ");
header('Expires: ');
header('Content-Type: ');
header('ETag: "'.$eTag.'"');
exit;
} else {
// We have to send them the whole page
header('Cache-Control: private');
header('Pragma: ');
header('Expires: ');
header('Last-Modified: '.gmstrftime("%a, %d %b %Y %T %Z",$lastModified));
header('ETag: "'.$eTag.'"');
}
}
下载标题
header("Server: SepidarSoft/ir-system");//server name
header("Date: ".date("a,d b Y H:M:S GMT",time()));
header("X-Powered-By: SepidarSoft");
header("Cache-Control: public");
header("Content-disposition:filename=\"".$BaseName."\"");//file name
caching_include($FPatch);//caching controller
header("Accept-Ranges:bytes");
header("Content-Transfer-Encoding: binary\n");
header("Connection: Keep-Alive");
header("Content-Type: $Type");//file type like application/zip
header("Content-Length: ".($FSize-$Cach)); //length of download it is for resume
header("Content-Range: bytes ".$Cach."-".($FSize-1)."/".$FSize); //download range it is for resume
header("HTTP/1.1 206 Partial Content",true);
set_time_limit(0);
如果set_time_limit(0);
在代码中使用如果用户连接断开 php 继续直到完成工作,您的文件将在一个请求后删除您下载或不下载,您可以使用connection_status()==0
如下检查连接
$Speed=102400;
fseek($Handle,$From);//if use resume it is useful
while(!@feof($Handle) and (connection_status()==0)){
print(fread($Handle,$Speed));
flush();
ob_flush();
}
if(connection_status()==0){//with this condition you can understand download is down by user
unlink($this->dirPath."/".$archive_file_name);
}