Home  >  Article  >  Backend Development  >  Struggling for 5 hours to solve the weird PHP problem - "Image XX cannot be displayed because it has errors"_PHP Tutorial

Struggling for 5 hours to solve the weird PHP problem - "Image XX cannot be displayed because it has errors"_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:15:011011browse

Yesterday, I finally migrated a client’s website to a virtual host and typed in the URL with great hope. With a snap, the website was opened easily. I feel so happy~~~ Hey, why are the product pictures not shown? Every block is blank. Type in the address corresponding to img src and see what's going on? The result shows the following effect:

This is what it looks like under IE:

No way, start the long debugging process. The solution steps are as follows:

1. Whether it is an error in the function code: follow the keyword image . . . Since there is something wrong with it and it cannot be displayed, I quickly googled a few solutions.

 Header("Content-type: image/PNG");这句代码前加上ob_clean();清除输出

Add ob_clean();

to the corresponding code location

There is no change in the running results.

PS: In order to locate this error, I used echo to output step-by-step debugging for a long time before locating the specific code.

2. Thinking: Why does it work well locally but fails when uploaded? Is it an environment configuration problem?

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

In order to compare the similarities and differences in the results returned by the Server, we 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 results.

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=1

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

The server returns the result:

Local return results:

The similarities and differences are: the server file header has one more

What is this? Continue searching and the result is the BOM header of UTF8. That is, there is an additional BOM header in the file returned by IIS.

For popular knowledge about UTF8, see: http://blog.csdn.net/hiruyue/article/details/8747221

3. Start checking which file was changed into UTF8 with BOM header, so I found a PHP version of the code to detect the BOM header, saved it as a PHP file, and sent it to the server. The result was quickly located. The system configuration file was changed to a file with a BOM header.

At this time, I remembered that after uploading the website using FTP, I used the editing tool that comes with FTP to modify the configuration file. It was modified using NOTEPAD at that time. That's it, quickly download the configuration file again, use NOTEPAD++ to change the file type to UTF8 without BOM, save, upload, and access. The website is finally back to normal.

Look at the time, 5 hours have passed.

PS: In the second step, I also saw that IIS sent an ICO file stream before sending the image binary stream, which also caused an error.

Conclusion:

After the modification was completed, I discovered Brother Orain’s article. He had similar problems to me. PHP uses streaming method to download files and UTF-8 BOM problem

Summary:

1. When you encounter a problem, first think about the cause and then solve it. Otherwise it's easy to get stuck in debugging code.

2. Search multiple times

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440234.htmlTechArticleYesterday, I finally migrated a client’s website to a virtual host and typed in the URL with great hope. With a snap, the website was opened easily. I feel so happy~~~ Hey, how come...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn