Fighting for five hours to solve the strange PHP-"image XX cannot be displayed due to its own mistakes"

Source: Internet
Author: User
Tags fiddler2

Yesterday, we finally migrated a customer's website to a VM and typed the website with hope. The website was opened easily. I am so happy ~~~ Why, no product images are displayed. Blocks are empty. Click the address corresponding to the img src to see what is going on? The result shows the following effect:

IE is like this:

No way, start a long debugging process. The solution is as follows:

1. Whether it is a function code error: According to the keyword image... Because of its own mistakes, it cannot be displayed, and soon google's several solutions.

Header ("Content-type: image/PNG"); add ob_clean () before this Code; clear the output

Add ob_clean () to the corresponding code location ();

The running result is unchanged.

PS: in order to locate the error, we used echo to output the debugging step by step for a long time before locating the specific code.

2. Thinking: Why is it so good locally that it is wrong to upload it? Is it a problem with environment configuration.

Local Environment XAMP, server environment: windows + IIS7.5.

To compare the similarities and differences between the results returned by the Server, it is decided to use Fiddler2 to track the similarities and differences between local access to the same file and Server access to the same file.

Open Fiddler2 and quickly locate the result.

Test address:

A、http://www.server.net/index.php?ac=public&at=zoom&filename=upfile%2F2011%2F08%2F30%2F20110830222415_540.jpg&w=&h=120&iszoom=1B、http://localhost:90/index.php?ac=public&at=zoom&filename=upfile%2F2011%2F08%2F30%2F20110830222415_540.jpg&w=&h=120&iszoom=1

Results returned by the server:

Local return results:

Similarities and Differences: the Server File Header has one more

What is this? Continue searching. The result is the BOM header of UTF8. That is, a BOM header is added to the file returned by IIS.

UTF8 universal knowledge see: http://blog.csdn.net/hiruyue/article/details/8747221

3. Check that the file has been changed to UTF8 with BOM header. Then, find the code for detecting the BOM header of a PHP version, save it as a PHP file, and upload it to the server. The system configuration file was changed to a file with BOM header.

At this time, I remembered that after uploading a website via FTP, I used the FTP built-in editing tool to modify the configuration file. It was modified with NOTEPAD. In the past, we had to download the configuration file again and use NOTEPAD ++ to change the file type to UTF8 without BOM, save, upload, and access. The website has finally recovered to normal.

Look at the time. Five hours have elapsed.

PS: in step 2, we also see that IIS sends an ICO file stream before sending the image binary stream, which also causes errors.

Conclusion:

After the modification, I found the article by the Orain brother. He encountered a problem similar to mine. BOM problem of PHP using stream download file and UTF-8

Summary:

1. if you encounter a problem, first think about the cause and then solve it. Otherwise, it is easy to tangle In the debugging code.

2. Multi-Search

 

 

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.