教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php 断点续传程序

php 断点续传程序

发布时间:2016-10-27   编辑:jiaochengji.com
教程集为您提供php 断点续传程序等资源,欢迎您收藏本站,我们将为您提供最新的php 断点续传程序资源

function sendfile($myFile){ 

 $mm_type="application/octet-stream"; 

$fp = fopen($myFile,'rb'); 

$size = filesize($myFile); 

ob_start(); 

header("Cache-Control: public, must-revalidate"); 

header("Pragma: hack"); 

header("Content-Type: " . $mm_type); 

header('Content-Disposition: attachment; filename="'.$fname.'"'); 

header("Content-Transfer-Encoding: binary "); 
if (isset($_SERVER['HTTP_RANGE']) && ($_SERVER['HTTP_RANGE'] != "") && preg_match("/^bytes=([0-9] )-/i", $_SERVER['HTTP_RANGE'], $match) && ($match[1] < $size)) { 

$range = $match[1]; 

fseek($fp, $range); 

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($myFile))." GMT"); 

header("Accept-Ranges: bytes"); 

$rangesize = ($size - $range) > 0 ? ($size - $range) : 0; 

header("Content-Length:".$rangesize); 

header("Content-Range: bytes ".$range.'-'.($size-1)."/".$size); 

//header("Connection: close"." "); 
}else{ 

header("Content-Length: ".(string)($size)); 

header("Accept-Ranges: bytes"); 

$range = 0; 


fpassthru($fp); 

ob_end_flush(); 
}

您可能感兴趣的文章:
php下载远程文件的类(支持断点续传)
php 断点续传的简单例子
断点续传原理是什么?怎么利用html5实现文件断点续传
PHP上传文件过大$_FILES为空的解决方法
PHP 中使用 TUS 协议来实现大文件的断点续传
调整PHP上传文件大小限制
H5怎么实现文件断点续传
php超大文件下载及断点续传下载的实现代码
Asp.net(c#)实现多线程断点续传
php断点续传下载示例代码

[关闭]
~ ~