首頁 > php教程 > PHP源码 > 主體

php 断点续传程序

WBOY
發布: 2016-06-08 17:27:15
原創
1329 人瀏覽過
<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(); 
}

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!