Is there a special MIME type (e.g. application/image
) that will enable the browser interpret a response as an image independent of the image type (pdf, gif, jpg)?
I have a server that automatically generates file names without extension for the uploaded images. What I want to avoid, is storing their extensions and to serve them to the clint using just the generated IDs. And I want to let the browser know it is an image, but without specifying the file extension.
No, the point of the MIME types is to identify the types of resources at the server level and allow the client to process them as is.
There are some image file types which do not have a binary signature marker (ex.: svg). Not having this marker makes the file hard to identify without a mimetype or file extension.
For example exif_imagetype
is a function which identifies GIF, JPEG, PNG, SWF, PSD, BMP, TIFF_II, TIFF_MM, JPC, JP2, JPX, JB2, SWC, IFF, WBMP, XBM, ICO but does not identify SVG files.
SVG files are XML files which describe the image structure in shapes, lines and points. So it's a text file, without the full proper mime type declaring that it's not only an image but an SVG image, it couldn't be treated as an image.
<!-- how do we handle this if the server
does not give as a mime type header? -->
<img src="file.svg" />
<!-- we know it's an image but what to do
with it -->
There are cases when css or js files are being generated using php and the extension is "*.php" and the developer hasn't set the correct "text/css" or "text/javascript" header, maybe the header is "text/plain", the browser will refuse to parse & apply them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With