|
本文介绍下,php实现断点续传的简单例子,有需要的朋友参考下。
分享一个php 断点续传的代码,供大家参考。 代码如下:
<?php
/**
* php断点续传
* edit by bbs.it-home.org
*/
$fname = './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 超大文件下载 断点续传下载 php 下载远程文件 支持断点续传 |
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号