PHP processing Large File download

Source: Internet
Author: User
Idea: PHP side Read File, while outputting the read to the browser

!--? php/** * Created by Phpstorm. * User:kung * date:15-10-21 * Time: Afternoon 8:00am */set_time_limit (0); Large files are timed out when the read content is not finished, resulting in incomplete download files. $fpath = & #39; the_file_path& #39;; $file _pathinfo = PathInfo ($fpath); $file _name = $file _pathinfo[& #39; basename& #39;];$ File_extension = $file _pathinfo[& #39; extension& #39;]; $handle = fopen ($fpath, "RB"); if (FALSE = = = $handle) exit ("Failed t o Open the File "), $filesize = FileSize ($fpath); Header (" CONTENT-TYPE:VIDEO/MPEG4 ");//More different file types Set header Output Type header (" Accept-ranges:bytes "), Header (" Accept-length: ". $filesize); header (" Content-disposition:attachment;    Filename= ". $file _name); $contents = & #39; & #39;; while (!feof ($handle)) {$contents = Fread ($handle, 8192);    Echo $contents;  @ob_flush ();      Release data from the PHP buffer to flush (); Send the released data to the browser}fclose ($handle); exit;  

Above the introduction of PHP processing large file download, including the content of reading files, I hope that the PHP tutorial interested in a friend to help Help.

  • 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.