May I ask questions about the HTTP response header during file download?

Source: Internet
Author: User
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.

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.