0

I want to know if there are advantages to keeping the extension of an image (on the client side, because on server side (linux), i do not see the benefits, knowing that the extension isn''t important).

Is it better to have <img src="/a" /> or <img src="/a.jpg" /> ?

So, store in server images with extension ?


Information: The images are photographs of the users. Names of the image is complex.

I'm thinking to keep extension, because if the user save the image, they will have extension.

But keep extension is a little more complicated for development. And it can be advantage to stay with no extension?

4

2 に答える 2

3

Typically, the extension is how the web server determines the MIME type for the file, which is how the browser knows it's an image and not text or arbitrary binary data or something else.

So, typically, you'd want to keep the extension just for that reason. There may be unusual situations where that may not be true, but in a typical web server serving files right off the filesystem, that's the case.

If you don't need the extension on the server side because you are sending the correct MIME type regardless of extension, then yeah, the only obvious advantage would be for situations where the user would want to save the image and the browser or OS isn't smart enough to do the right thing with the image without an extension. In this day and age, I have no idea how common that situation is but it is certainly less common than it used to be.

Personally, I'd be disinclined to worry about it if it will complicate development for you (especially if it's something you can always go back and do if you find out that you actually do need it for some reason). What I would ponder, though, is if there is something that needs to be improved in the application architecture if preserving the file extension is a big headache. It seems like that shouldn't be a big deal one way or the other. Of course, I say that without knowing the particulars of your situation; I'm just speaking in generalities.

于 2012-07-14T17:57:30.080 に答える
0

Not using extension should be fine as long as you send the correct MIME types. Browsers automatically add extensions if required. (Prove: Your Gravatar picture: http://www.gravatar.com/avatar/f1f8a3382d2946bd526dd629eaa29b2b?s=32&d=identicon&r=PG)

Basically you can use any extension as long as the MIME type is correct. If you serve your files statically using extension would be more convenient since most Webservers use extension-based MIME-type guessing. Serving from a database not using extensions could be more convenient...

于 2012-07-14T17:59:26.223 に答える