断点继传

上一篇 / 下一篇  2007-11-02 17:51:50 / 个人分类:技术技巧

/* 
* @url: 文件地址 
* @filename: 要保存的文件名 
*/ 
function _download($url$filename


// 获得文件大小, 防止超过2G的文件, 用sprintf来读 
$filesize sprintf("%u"filesize($url
)); 

if (!
$filesize


return; 


header("Content-type:application/x-msdownload\n"); 
//application/octet-stream 
header("Content-type:unknown/unknown;"
); 
header("Content-disposition: inline; filename=\"".$filename."\""
); 
header('Content-transfer-encoding: binary'
); 

if (
$range getenv('HTTP_RANGE')) 
// 当有偏移量的时候,采用206的断点续传头 

$range explode('='$range
); 
$range $range[1
]; 

header("HTTP/1.1 206 Partial Content"
); 
header("Date: " gmdate("D, d M Y H:i:s") . " GMT"
); 
header("Last-Modified: ".gmdate("D, d M Y H:i:s"filemtime($url))." GMT"
); 
header("Accept-Ranges: bytes"
); 
header("Content-Length:".($filesize $range
)); 
header("Content-Range: bytes ".$range.($filesize-1)."/".$filesize
); 
header("Connection: close"."\n\n"
); 

else 

header("Content-Length:".$filesize."\n\n"
); 
$range 0



$fp fopen($url'rb'
); 
fseek($fp$range
); 
while (
$bbsf fread($fp4096
)) 

echo 
$bbsf


fclose($fp
); 

}

TAG: 技术 技术技巧

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

数据统计

  • 访问量: 142
  • 日志数: 2
  • 建立时间: 2007-10-31
  • 更新时间: 2007-11-02

RSS订阅

Open Toolbar