【www.gdgbn.com--安卓教程】

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

本文来源:http://www.gdgbn.com/shoujikaifa/24731/