我們來看看用php 斷點續傳吧,這個功能很好的節省時間
我們來看看用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;
?>