This article illustrates the method of PHP implementing HTTP breakpoint Continuation. Share to everyone for your reference. The implementation methods are as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 This is the |
; > <?php/** * php-http Breakpoint Continuation * @param string $path: File is in the path * @param string $file: file name * @return void */function Downlo AD ($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.