tags:

views:

88

answers:

3

I have a web application that will display logos. Some of the logos will be in GIF format. Some will be in JPEG format.

I'd like to standardize a file naming convention, so that I can find the logo file given the company's Primary Key. For example "British Petroleum" has a PK of 1459, and their logo is stored in /Images/Logos/C1459

So my question is this:

Are the file extensions important? Can I just save the files, and strip off the .JPG or .GIF and expect all browsers to be able to identify and render the file? Or do some broswers rely on the file extension for identification?

I've tried this on a test machine with IE7 and it works fine, but I don't want to assume that all other browsers work the same.

EDIT: A Follow up question. Hows does IIS determine the MIME Type of a extension-less file?

+2  A: 

You'll definitely want to test it in as many browsers as possible, but it should be fine. As long as the file format is correct and the MIME type is being conveyed properly, the browser should merrily display the image just fine. (A lot of sites will have "images" with URLs like: /images/dbimage.aspx?id=123)

Edit: More important to the testing than different browsers, actually, is different image types. If there are any image types that don't get sent with the correct MIME type, you'll want to identify those and either address them or disallow them.

David
+8  A: 

More important to a browser is the MIME type transmitted along with the file during download - historically, some did fall back to heuristics such as file extension or trying to calculate based on the bytes transmitted, but if the MIME type is correct, there would be no need.

Rowland Shaw
And the anonymous downvote was because?
Rowland Shaw
Have an upvote, not anonymous, and even as explanation as to why: Concise, Correct, and taught me an interesting bit of extra information to boot.
nearlymonolith
Indeed, the MIME type is the only thing to worry about. In the past, browsers attempted to select a file type according to the extension, but I don't think many that do that will exist today. BTW, I once posted a JPEG picture to a forum and then concluded that it wasn't the most suitable file type. I changed the image to PNG8, but saved it with exact the same file name, so with the extension .jpg. The file was served with the correct MIME type (and IIRC it was hosted on an IIS server).
Marcel Korpel
A: 

This seems a bit back-to-front to me. Why not:

1) Convert all images to the same type when you first store them?

or

2) Search for a company's image using a wildcard search (ie match /Images/Logos/C1459.*) and load the file that returns a positive match. As you are using primary keys, you can be confident that you should only find one match for each company.

MatW
1) Because converting between gif and jpeg loses information (jpeg is lossy and gif supports less colors). 2) because it's more complicated.
Brendan Long
…and images are saved using a sub-optimal file-type (e.g.: using JPEG to store line drawings is generally a bad idea, especially with company logos, and I've seen lots of ugly images due to using the wrong image format, probably because of the misconception I hear sometimes that “JPEG produces always the smallest files”).
Marcel Korpel