php断点续传下载示例代码
例子,php断点续传下载的实例代码。
$fname = './test.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下载远程文件的类(支持断点续传)
php断点续传下载示例代码
php 断点续传的简单例子
php超大文件下载及断点续传下载的实现代码
php支持断点续传的文件下载类(附源码)
php大文件下载代码(支持断点续传)
PHP上传文件过大$_FILES为空的解决方法
PHP支持断点续传的下载代码
php下载远程文件的类(断点续传)实例分享
php断点续传分割合并文件实例代码