PHP Code: HTTP Breakpoint Continuation Implementation Example _php tutorial

Source: Internet
Author: User
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 *...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.