我们来看看用php 断点续传吧,这个功能很好的节省时间
我们来看看用php 断点续传吧,这个功能很好的节省时间
header("Cache-Control: public");
header("Accept-Ranges: bytes");
$file = "a.rar";
$filename = "a.rar";
$size=filesize($file);
$size1=$size-1;
//获得字节范围
if(isset($_SERVER['HTTP_RANGE'])) {
list($name, $range) = explode("=",$_SERVER['HTTP_RANGE']);
$length=$size1-$range;
header("HTTP/1.1 206 Partial Content"); //http协议头状态码,表示以部分内容传输
header("Content-Range: bytes ".$range."-".$size1."/".$size);
}else{
$length = $size;
}
header("Content-Length: $length");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$filename);
$fp=fopen($file,"rb");
//设定文件指针位置
fseek($fp,$range);
while(!feof($fp)){
set_time_limit(0);
echo fread($fp,1024);
flush();
ob_flush();
}
fclose($fp);
exit;
?>