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