Please consult the HTTP response message header when downloading the file.
When I was learning to use PHP for file downloads, the textbook said it needed to provide three HTTP message headers:
PHP Code
Header ("Content-type:application/octet-stream"); The high-speed browser passes the 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:
PHP Code
b.php:
PHP Code
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! :)
------Solution--------------------
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.