PHP File Download

Source: Internet
Author: User

PHP file download is not complex, still follow the principle of HTTP protocol, a request corresponding to a response,

And then actually a text is a stream of files composed of

Otherwise you casually open a picture, inside with binary view actually is a lot of binary code composition of things, so plainly

Download: That is, the string of encrypted binary file saving process, as for the resolution is the application of their own computer things

A few things to note:

The function of the header ("Content-type:text/html;charset=utf-8"): When the server responds to the browser's request, tells the browser to display the content in encoded format as UTF-8 encoding
About the file_exists () function does not support the Chinese path problem: Because the PHP function is earlier, does not support Chinese, so if the file name is downloaded in Chinese, it needs to be converted to character encoding, otherwise the file_exists () function is not recognized, you can use the Iconv () function for encoding conversion
$file _sub_path () I'm using an absolute path, and execution is more efficient than a relative path.
The function of the Header ("Content-type:application/octet-stream"): Through this code the client browser can know the file form returned by the server
The role of the Header ("Accept-ranges:bytes"): tells the client that the file size returned by the browser is calculated in bytes
Header ("Accept-length:". $file _size): tells the browser the size of the file returned
Header ("content-disposition:attachment; Filename= ". $file _name): Tell the browser the name of the file returned
The above four headers () are required
fclose ($FP) can output the last remaining data in the buffer to a disk file, releasing the file pointer and the associated buffer

PHP File Download

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.