Recently, when developing a website based on PHP, I encountered a very strange problem, that is, images cannot be displayed in the IE browser. This bothers me because the image displays fine in other browsers, only IE has problems.
After some investigation, I found that the root cause of the problem was that the image file name contained spaces or Chinese characters. Since IE's cache management mechanism is different from other browsers, when the image file name contains spaces or Chinese characters, IE will automatically encode it into Url encoding, but other browsers will not.
Specifically, when an image file name contains spaces or Chinese characters, IE will convert it into the following form:
http://example.com/images/Picture test .jpg
The picture is the Url encoding form of the Chinese character "picture", and is the Url encoding form of the space.
However, when referencing such an image in PHP, it needs to be decoded back to its original form, otherwise it cannot be displayed. Specifically, when using PHP's img tag to reference an image, the image path needs to be decoded through the urldecode() function, as shown below:
In this way, the image can be displayed normally in IE.
In addition, there are some other solutions, such as using the urlencode() function to encode the image path, or replacing spaces and Chinese characters in the image file name with other characters. However, these methods may cause other compatibility issues, so it is best to use the urldecode() function to decode to be compatible with all browsers.
In general, through this experience, I deeply realized the differences in encoding processing between different browsers, and I need to be extra careful during development.
The above is the detailed content of PHP website ie pictures do not display pictures. For more information, please follow other related articles on the PHP Chinese website!