PHP Code: an example of an implementation of HTTP breakpoint continuation
Copy to ClipboardWhat to refer to: [www.bkjia.com]
/**
* Php-http Breakpoint Continuous Transmission implementation
* @param string $path: The path where the file is located
* @param string $file: File name
* @return void
*/
function Download ($path, $file) {
$real = $path. ' /'. $file;
if (!file_exists ($real)) {
return false;
}
$size = FileSize ($real);
$size 2 = $size-1;
$range = 0;
if (Isset ($_server[' Http_range ')) {
Header (' http/1.1 206 Partial Content ');
$range = str_replace (' = ', '-', $_server[' Http_range '));
$range = Explode ('-', $range);
$range = Trim ($range [1]);
Header (' Content-length: '. $size);
Header (' Content-range:bytes '. $range. '-'. $size 2. ' /'. $size);
} else {
Header (' Content-length: '. $size);
Header (' Content-range:bytes 0-'. $size 2. ' /'. $size);
}
Header (' accenpt-ranges:bytes ');
Header (' Application/octet-stream ');
Header ("Cache-control:public");
Header ("Pragma:public");
Solve the problem of Chinese garbled when downloading in IE
$ua = $_server[' http_user_agent ');
if (Preg_match ('/msie/', $ua)) {
$ie _filename = str_replace (' + ', '%20 ', UrlEncode ($file));
Header (' content-dispositon:attachment; filename= '. $ie _filename);
} else {
Header (' content-dispositon:attachment; Filename= '. $file);
}
$fp = fopen ($real, ' rb+ ');
Fseek ($fp, $range);
while (!feof ($fp)) {
Set_time_limit (0);
Print (Fread ($FP, 1024));
Flush ();
Ob_flush ();
}
Fclose ($FP);
}
/*end of php*/
http://www.bkjia.com/PHPjc/363905.html www.bkjia.com true http://www.bkjia.com/PHPjc/363905.html techarticle PHP Code: HTTP Breakpoint Continuation of the implementation example Copy to Clipboard reference: [www.veryhuo.com]? PHP/** * php-http Breakpoint Continuation Implementation * @param string $path: The path of the file *...