首页  >  文章  >  php教程  >  php 断点续传程序

php 断点续传程序

WBOY
WBOY原创
2016-06-08 17:27:151321浏览
<script>ec(2);</script>

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]

$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(); 
}

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn