This article illustrates the method of PHP implementing HTTP breakpoint Continuation. Share to everyone for your reference. The implementation method is as follows:
<?php/** * php-http Breakpoint Continuation * @param string $path: File is in the path * @param string $file: file name * @return void/function do Wnload ($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 Chinese garbled problem 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); }
I hope this article will help you with your PHP programming.