For more information, see the HTTP response header when downloading files. When I learned how to use PHP to download files, the textbook said that three http message headers are required: PHPcodeheader (& quot; Content-type: applicationoctet-stream & quot ;); the high-speed browser transmits the File Stream header (& quot; Acce asks about the HTTP response header when the file is downloaded.
When I learned how to use PHP to download files, the textbook said that three http message headers should be provided:
PHP code
Header ("Content-type: application/octet-stream"); // The high-speed browser transmits the file stream header ("Accept-Length: 2048 "); // file size header ("Content-Disposition: attachment; filename=abc.txt"); // specify the file name
The message headers "Content-type" and "Content-Disposition" are not quite understandable, so I have made two examples:
A. php:
PHP code
B. php:
PHP code
My problem is:
1. there is one missing message header on both pages. Why can all files be downloaded successfully?
2. although the size of the specified file is 2048 bytes, the actual output is only "123". Why can the file be downloaded normally?
Is the "Accept-Length" message header configurable?
I have just learned about http. please answer the questions I have asked. do not introduce a deeper concept because I cannot understand it ..
Thank you! :)
------ Solution --------------------
1. there is one missing message header on both pages. Why can all files be downloaded successfully?
Because you have not set the Content-Length, the output at the end of the default connection is the downloaded Content.
2. although the size of the specified file is 2048 bytes, the actual output is only "123". Why can the file be downloaded normally? Is the "Accept-Length" message header configurable?
Accept-Length indicates the maximum acceptable string Length. So it can be set.