For more information, see the HTTP response header when downloading files. At last, this post was edited by love_u_qt in 2012-08-0515: 08: 30. when I learned how to use PHP to download files, the textbook said that three http message headers should be provided: header (Content-type: & nbsp; applicationoctet-stream ask the question about the HTTP response header during file download.
This post was last edited by love_u_qt at 15:08:30
When I learned how to use PHP to download files, the textbook said that three http message headers should be provided:
Header ("Content-type: application/octet-stream"); // A high-speed browser transmits a 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:
header("Content-type: application/octet-stream");
header("Accept-Length: 2048");
echo 123;
B. php:
header("Accept-Length: 2048");
header("Content-Disposition: attachment; filename=abc.txt");
echo 123;
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.