当前位置:首页 > PHP教程 > PHP高级教程

PHP简单实现断点续传下载的方法

本文实例讲述了php实现断点续传下载的方法。分享给大家供大家参考。具体如下:

$fname = 'http://xxxx/mmldzg.mp3';
$fp = fopen($fname,'rb');
$fsize = filesize($fname);
if (isset($_server['http_range']) && ($_server['http_range'] != "") && preg_match("/^bytes=([0-9]+)-$/i", $_server['http_range'], $match) && ($match[1] < $fsize)) {   $start = $match[1]; } else {   $start = 0; } @header("cache-control: public"); @header("pragma: public"); if ($star--> 0) {
  fseek($fp, $start);
  header("http/1.1 206 partial content");
  header("content-length: " . ($fsize - $start));
  header("content-ranges: bytes" . $start . "-" . ($fsize - 1) . "/" . $fsize);
} else {
  header("content-length: $fsize");
  header("accept-ranges: bytes");
}
@header("content-type: application/octet-stream");
@header("content-disposition: attachment;filename=mmdld.mp3");
fpassthru($fp);
fpassthru();//函数输出文件指针处的所有剩余数据。

该函数将给定的文件指针从当前的位置读取到 eof,并把结果写到输出缓冲区。


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!