Example of getting the downloaded file size Using Accept-Length in php-PHP source code

Source: Internet
Author: User
When we use php to download a file, you will find that the file to be downloaded is large, but the developer does not use Accept-Length to obtain the downloaded file size, next let's take a look at the example of how to get the size of the downloaded file using Accept-Length. When we use php to download a file, you will find that the downloaded file is too large to be known, the developer does not use Accept-Length to obtain the downloaded file size. Let's take a look at the example of Accept-Length to obtain the downloaded file size.

Script ec (2); script

When downloading files in php, add the following header information:

Header ("Content-type: application/octet-stream ");

Header ("Accept-Ranges: bytes ");

Header ("Accept-Length:". $ fileSize );

Header ("Content-Disposition: attachment; filename =". $ fileName );

I have added header ("Accept-Length :". $ fileSize); in this case, the size of the downloaded file cannot be obtained. Although it does not affect the normal functions, I have to find out whether it is perfect.

Check the manual, search for information, and finally find the header ("Accept-Length: ***"). This is actually misleading. I really don't understand why Accept-Length is the same on the Internet. The correct one should be the header ("Content-Length: *** "); After modification, it is correct, such as the effect.

After you change Accept-Length to Content-Length, you can identify the size of the downloaded file.

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.