PHP简单实现断点续传下载的方法
发布人:shili8
发布时间:2022-12-01 04:05
阅读次数:33
本文实例讲述了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,并把结果写到输出缓冲区。
希望本文所述对大家的php程序设计有所帮助。

