How to make Internet Explorer display .PNG image i

2019-08-08 01:41发布

问题:

For example, I wish IE could display png image, represented by URL "http://update1.osmp.ru/logos/7642909813539583507":

<html>
    <head>
        <title>Failed to display png image that comes without .png extension in URL</title>
    </head>
    <body>
        <img src="http://update1.osmp.ru/logos/7642909813539583507">
    </body>
</html>

It doesn't work because http://update1.osmp.ru/logos/7642909813539583507 is not resolved as PNG file by IE. Is there any workaround, plug-in, whatever to display such a url resource in IE using img tag?

回答1:

There's no such thing as a file extension in a URL. Just things that look like file extensions and might happen to map on to a file with one on the file system.

It is the content type that determines how an HTTP resource will be handled, and if you examine that one…

[ david ][ david@raston ] %  lynx -dump -head "http://update1.osmp.ru/logos/7642909813539583507"
HTTP/1.1 200 OK
Date: Wed, 07 Oct 2015 09:24:16 GMT
Content-Type: text/plain

… you'll see that the server claims it is a plain text file and not a PNG image (image/png).

You need to fix the server so it sends the correct content type.

How you do this will depend on the server and any server side software you are using to generate the image.

For instance, if you are serving up a static file which doesn't have a file extension (servers normally use the file extension on the file system to determine the content type for static files) and you are using Apache HTTPD, then you could use the ForceType directive.

e.g. in your server configuration:

<Location /logos/>
    ForceType image/png
</Location>


回答2:

The problem is the Content-Type header of your response. It is text/plain, but it must be image/png.

The Content-type is set by the server that return the image. You should have a look at your server configuration.