views:

24

answers:

1

I'm looking to handle image extentions .jpg, .png, .gif, etc. Essentially, what I have is a webserver that takes an image and archives it on the basis of its SHA-1. I use the git convention a1\b2\XXXXXX... with the hex representation of the digest. My question is how is it best to store the extension in the database? Am I safest storing the MIME type? Or, the original file type? Or, should I just auto-generate the MIME each time? Should I store the mime-type the original client sent in the HTTP upload?

As a side note, does IE7+ handle images without file extensions? Is it safe to just send them out without them?

Any other advice on web servers and image types?

+3  A: 

Screw the extension. Use libmagic to figure out what it really is and send it out like that. But of course you're going to make sure that the extension matches the file contents in the first place, right?

Ignacio Vazquez-Abrams
Why do I care? If I'm using libmagic and ignoring the extension I need to only be concerned that I've got an image right? If they send a `.gif`, as a `.jpg` and I use libmagic than I can even handle such silliness transparently..
Evan Carroll