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.