Using PHP for file download

Source: Internet
Author: User
here is how to use PHP to implement the file download program, mainly for the convenience of their own search, but also for the convenience of people to access to learn (of course, there are other similar code on the Internet). The detailed analysis of the original program comments.

PHP implementation file Download program:


 10*1024*1024) {echo ""; return;} *///4. Add HTTP response information//return the file header ("Content-type:application/octet-stream");//return header by byte size ("Accept-ranges:bytes ");//Returns the file size header (" Accept-length: ". $file _size);//The Client's popup dialog box, corresponding to the filename header (" content-disposition:attachment; Filename= ". $file _name);//5. Send the data back to the client $buffer=1024;//in order to download the security, we'd better make a file byte read counter $file_count=0;//This sentence is used to determine whether the file ends while (! Feof ($fp) && $file _size-$file _count>0) {$file _data=fread ($fp, $buffer);//Statistics read the number of bytes $file_count+= $buffer ;//Send some data back to the browser echo $file _data;} 6. Close file fclose ($fp);}? >

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the use of PHP to implement file download, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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