Can you tell me something about the HTTP response message header when the file was downloaded?

Source: Internet
Author: User
Please consult the HTTP response message header when downloading the file.
This post was last edited by love_u_qt on 2012-08-05 15:08:30

When I was learning to use PHP for file downloads, the textbook said it needed to provide three HTTP message headers:

Header ("Content-type:application/octet-stream"); A high-speed browser passes a file stream
Header ("accept-length:2048"); File size
Header ("content-disposition:attachment; Filename=abc.txt "); Specify file name


Of these, "Content-type" and "content-disposition" two message headers, I still a little bit not understand, so I did two separate 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 question is:
1, these two pages are less a message header, why can still successfully download files?
2, although I specify the size of the file is 2048 bytes, but the real output only "123" three bytes, why can i download the file as normal?
"Accept-length" message header is can be set can not set it?

I just learned http, trouble people to answer the questions I asked, do not draw a deeper concept, because I can not understand.
Thank you very much! :)
------to solve the idea----------------------
1, these two pages are less a message header, why can still successfully download files?

Because you do not set content-length, the output at the end of the default connection is the download content.

2, although I specify the size of the file is 2048 bytes, but the real output only "123" three bytes, why can i download the file as normal? "Accept-length" message header is can be set can not set it?

Accept-length means the length of the maximum acceptable string. So it can be set to No.
  • 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.