HTTP Shard Download File code

Source: Internet
Author: User
Tags ranges

function Download ($sourceFile, $outFile = ') {//begin Writing headers header ("Cache-control:")        ;        Header ("Cache-control:public");        Set the Output browser format header ("Content-type:application/force-download"); Header ("content-disposition:attachment; Filename= ".        $outFile);        Header ("Accept-ranges:bytes");        Header ("Content-type:application/force-download");        Header ("Cache-control:");        Header ("Cache-control:public"); Header ("content-disposition:attachment; Filename= ".        $outFile);        Header ("Accept-ranges:bytes");            $size = FileSize ($sourceFile);        If there is a $_server[' http_range '] parameter $httprange = $_server[' Http_range '); The value bytes=4390912-list ($a, $range) = Explode ("$httprange) {//breakpoint after connecting $_server[' Http_range ']            = ", $_server[' Http_range ']); If yes, download missing part $size 2 = $size; Total Files bytes $new _length = $size 2-$range; Gets the length of the next download header ("http/1.1 206 Partial Content"); Header ("Content-length: $new _length"); Enter the total length header ("Content-range:bytes {$range}-{$size 2}/{$size}");            Content-range:bytes 4908618-4988927/4988928 95%} else {//first connection $size 2 = $size-1; Header ("Content-range:bytes 0-{$size 2}/{$size}"); Content-range:bytes 0-4988927/4988928 Header ("Content-length:". $size);        Output total length}//Open File $fp = fopen ("{$sourceFile}", "RB");        Set pointer position fseek ($FP, $range);         Unreal output Ob_clean ();            while (!feof ($fp)) {//Set file Maximum execution time set_time_limit (0); Print (Fread ($FP, 1024 * 1)); Output file flush ();        Output buffer Ob_flush ();             } fclose ($FP);    return true; }



HTTP Shard Download File code

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.