Use PHP to download the file can not open, the use of their own no problem, customers do not?

Source: Internet
Author: User

1 Phenomenon:

Development time with a good file download function, deployment to the customer side is not good, almost all the files downloaded from the server can not be opened.

Compare the pre-upload files, upload the server side of the file, after downloading the file, found the same file, upload also good, through php downloaded 3 more bytes.

Open file with Uediter in 16 binary mode find the file header more than "EF BB BF" This three bytes.

2 Analysis:

It's easy to get to the Internet. These three bytes are called BOM headers, which Windows uses to identify this file as a UTF8 format.

At first it was easy to think of a fork, such as deleting the BOM header when downloading a file, such as forcing Windows to not add this BOM header when downloading, but the above method is impossible to achieve.

Finally see a big God in a message said, if the PHP file itself with a BOM header, then the file downloaded through this PHP file will automatically be added to the BOM header!

So I downloaded the server-side PHP file, found that the server side of the PHP file is really more than this three bytes! And my local PHP file does not!

So where did these three bytes come from?

  Because the client edited the file with Notepad before uploading the PHP file!!!!!!

Because we use the compiler, when considering the Chinese problem, the PHP file will generally be set to UTF-8 format, the entire project is utf-8.

If you use Notepad to edit the utf-8 format of the file, the system will automatically add a BOM header, note this is a utf-8 format file, the system is convenient to identify this file!!!

The ultimate reason or because the PHP development time did not take into account the Chinese problem, so must use Utf-8 format, and the operating system in order to facilitate their own to the front of the file plus BOM header!

So the chance coincidence, see this article of you, also encountered this problem.

3 Solution:

It is easy to send a PHP file that has not been edited by Notepad to the customer to solve the problem!

And told customers not to use Notepad to open these files!!!

Use PHP to download the file can not open, the use of their own no problem, customers do not?

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.