Using PHP to implement file upload support breakpoints

Source: Internet
Author: User
Tags ranges
Using PHP to implement file download support breakpoints
File download with PHP, with support for the next breakpoint form
            Ob_start ();            $size = FileSize ($file _dir. $file _name);            Enter the file label Header ("Content-type:application/octet-stream");                        Header ("Cache-control:must-revalidate, Post-check=0, pre-check=0"); Header ("Content-length:".)                        $size);            $encoded _filename = UrlEncode ($down _name);            $encoded _filename = str_replace ("+", "%20", $encoded _filename);            $ua = $_server["Http_user_agent"]; When processing the download file name if (Preg_match ("/msie/", $ua)) {header (' content-disposition:attachment; filenam E= "'. $encoded _filename.            '"'); } else if (Preg_match ("/firefox/", $ua)) {header (' content-disposition:attachment; filename*= ' utf8\ ' \ '). $down _name.            '"'); } else {header (' content-disposition:attachment; filename= '. $down _name.            '"'); } $fp = fopen ($file _dir. $file _name, "R"); Open File if(Isset ($_server[' Http_range ') && ($_server[' http_range ']! = ") && preg_match ("/^bytes= ([0-9]+)-/i "                                , $_server[' Http_range ', $match) && ($match [1] < $size)) {$range = $match [1];                Fseek ($fp, $range);                Header ("http/1.1 206 Partial Content"); Header ("Date:".) Gmdate ("D, D M Y h:i:s").                "GMT"); Header ("last-modified:".) Gmdate ("D, D M Y h:i:s", Filemtime ($file _dir. $file _name)).                "GMT");                Header ("Accept-ranges:bytes"); $rangesize = ($size-$range) > 0?                ($size-$range): 0; Header ("Content-length:".)                $rangesize); Header ("Content-range:bytes". $range. '-' . ($size-1). "/" .                $size); Header ("Connection:close".                "\ n"); Header ("Connection:close". "            "); } else {header ("Content-length:". (string)               ($size)); Header ("Accept-ranges:bytes");                $range = 0; Header ("Content-range:bytes". $range. '-' . ($size-1). "/" .            $size);            } fpassthru ($FP);            Ob_end_flush ();            Fclose ($FP); Exit

This will allow the breakpoint to be downloaded. Want to use PHP to achieve the download of friends useful

  • Related Article

    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.