PHP implementation of HTTP breakpoint continuation of the method, PHP implementation of the breakpoint to continue to pass
In this paper, we describe 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 Implementation * @param string $path: File path * @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);}
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1018517.html www.bkjia.com true http://www.bkjia.com/PHPjc/1018517.html techarticle PHP Implementation of HTTP breakpoint continuation of the method, PHP implementation of the breakpoint continuation of this article describes the PHP implementation of HTTP breakpoint continuation of the method. Share to everyone for your reference. The specific implementation method is as follows: ph ...