0

I was wondering if there are any implications if the filename specified in the src attribute for the <img> tag is different than the actual image format

for example, I can have an image with an extension like

  <img src="avatar.pdf" alt="" />

or

  <img src="avatar.html" alt="" />

and it still works.

Content-Type in the response headers are obviously different in each case, but I guess web-browsers ignores it.

Given that there are so many platforms and web-browsers versions, are there any implications?

Background:

The reason I am asking this is because I am working on an web app where you can create HTML content with images. Same image can be referenced in different places (user can select an image from repository). I need to let user replace an image but without the need for the system to re-save all the HTML pages which use that image. The image path has to be based on an id which is tracked in database. But the problem is with file extension when image is replaced. My idea is to keep image files without any extension, i.e:

  <img src="/Content/Images/1289371" alt="" />
WriteEatSleepRepeat
  • 3,083
  • 3
  • 33
  • 56

2 Answers2

0

Possible duplicate: Can I use images without extension in <img>?

Short answer:

Content-Type in the response headers are obviously different in each case, but I guess web-browsers ignores it.

=> No it doesn't.

Browsers initially don't look at the filename, they look at the MIME type listed in the Content-type header in the response from the HTTP server. If the content type is image/jpeg, or png or gif or whatever, things are good and it will happily render the image.

If there is no valid MIME type, some browsers will try to guess what the type is. They'll look at the extension of object being request, or they'll look at the first few bytes. If that fails, then you get a redex.

All credit to whatsisname

Community
  • 1
  • 1
Aegis
  • 1,749
  • 11
  • 12
0

I think the webbrowser will check the binary content of those files and ignore the extension etc.

It is pretty simple to just check the first bytes for a browser to look for headers.

Jennifer
  • 11
  • 1
  • 3
    Welcome to Stack Overflow, @Jennifer! Please take a look at stackoverflow.com/about to see the format of answers. Please also provide instructions on how to "check the first bytes for a browser to look for headers", since it's a bit unclear what you mean by this. Also make sure to perhaps reference a source for your first claim. (The fact that it starts with "I think" make me feel less sure about what you're saying, and it doesn't really give me the feeling that that's the answer.) – arturomp Sep 05 '13 at 22:55