Question about IMG tags and file names

R

Rob

Do browsers determine the type of a file by either looking at it's contents
or it's file name when parsing an IMG tag? IE7 can be asked to display
"Photo.tmp" which is actually a JPG and it displays it correct.

Just worried that other browsers may to it a different way.

The reason it's called TMP is that the file is coming out of a SQL IMAGE
field and I don't have the original file name to hand.

Cheers< Rob.
 
E

Eliyahu Goldin

Are you saying you are saving the image in a file? This is unnecessary. The
standard way of serving database images is making a special page
GetImage.aspx that will get images from the database and stream them down
top the client in the http response. The image url will look like
"GetImage.aspx?id=xxx"/

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
R

Rob

Are you saying you are saving the image in a file? This is unnecessary.

The image is saved in a database. Imagine a gallery of photos like on
facebook. The application extracts the image from the database, writes it
into a file and then generates IMG tags to point to the download files.

It has to work this way - the generated pages are static, only updated
periodically.

So an IMG tag has to be used - the question is how to, with an IMG tag, does
the browser work out what type of file it is? Does it a) look and the
extension or b) look at the file header.

And if (b) is that true for all browsers?

Cheers, Rob.
 
E

Eliyahu Goldin

The image is saved in a database. Imagine a gallery of photos like on
facebook. The application extracts the image from the database, writes it
into a file and then generates IMG tags to point to the download files.

It has to work this way - the generated pages are static, only updated
periodically.
Still the standard solution looks better to me. There is absolutely no
advantages in using files. You have to take care of deleting them, of file
naming, of scalability.
So an IMG tag has to be used - the question is how to, with an IMG tag,
does the browser work out what type of file it is? Does it a) look and the
extension or b) look at the file header. b)


And if (b) is that true for all browsers?
To be 100% sure, you need to investigate about every browser separately.
For Mozilla this source
http://developer.mozilla.org/en/docs/How_Mozilla_determines_MIME_Types says:
....for images loaded via <img src>, Mozilla's image library will do content
sniffing (never extension sniffing) to find out the real type of the image.

Look also in this: HTTP content-type and browser support
http://www.byteflex.co.uk/http_content_type_and_browser_support.html


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top