Forum Moderators: phranque

Message Too Old, No Replies

Images with no extension display strange characters

         

meade999

11:26 am on Nov 25, 2010 (gmt 0)

10+ Year Member



Hi everyone,

I was wondering if someone could help me?

I have imported some products to my website and used a script that imports external images and saves them to my server. Some of the images do not have extensions, and if i try to view the image directly in the browser i get a whole page of this:

ÿØÿà�JFIF��H�H��ÿÛ�„�


The images display fine in the backend of my website though, but just not when directly viewing the image in a browser.

Although as Im writing this, ive just noticed this only happens in forefox and not IE8.

Is this an apache thing and IE just recognises the error? Or is it a Firefox problem?

Any help would be much appreciated.

thanks

g1smd

11:29 am on Nov 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Images should have an extension.

This tells the browser what type of image it is.

It is pages that can go extensionless.

meade999

11:39 am on Nov 25, 2010 (gmt 0)

10+ Year Member



Hi,

Thanks,

Is there any way of it not having an extension?

I cant control that, as the images are imported remotely and the remote servers images do not have extensions.

thanks

g1smd

10:33 am on Nov 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use the Live HTTP Headers extension for Firefox to investigate the MIME type details sent in the server response.

jdMorgan

8:22 pm on Dec 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Files should have extensions to tell the server what MIME-type to send with their content. It is the MIME-type sent in the HTTP Content-Type response header which tells the browser how to render the image.

In the case of your back-end-script-controlled image serving, the script is likely outputting this Content-Type header, but when you access the image directly (as a static resource), the server cannot identify the content-type because the file has no extension. it is likely being sent with a type of text/plain, resulting in the odd display on your screen.

Firefox (and all other HTTP-compliant browsers) rely on the Content-Type header. IE, on the other hand, ignores this header and actually looks at the content-body, and "figures out" what the content-type must be (or more accurately, what it probably must be, since it makes mistakes occasionally).

So the key here would be to declare a default MIME-type for extensionless files, but that will only work if all images are of the same type. If you are serving a mix of jpg, gif, and png, then there will be no good solution except to replicate the "figure it out" function of MSIE on the server-side -- Open the file, look at the first few bytes, and see if it has "GIF89A" or "JFIF" or whatever in it, and then use the script to send a correct Content-Type header along with the file contents.

You'll want to use a rewriterule to rewrite requests for extensionless URLs to this script.

Of course, none of this is needed unless you plan to serve those images directly, and not using your "back-end" script.

Jim