NYCPHP Meetup

NYPHP.org

[nycphp-talk] Determining mime type of data not a file

Mikko Rantalainen mikko.rantalainen at peda.net
Thu Jan 26 08:58:11 EST 2006


Scott Mattocks wrote:
> Chris Merlo wrote:
>>On 1/25/06, Scott Mattocks <scott at crisscott.com> wrote:
>>
>>>I am looking for a way to determine the mime type of an image that is
>>>held in memory and does not come from a file.
>>
>>Scott:
>>If that cache class is something you wrote, just add a mimeType data field
>>to it, and store the mime type when you cache the image.
> 
> The cache class is an in house class that I can't really mess with. It 
> holds a lot of other types of data besides images and we want it to stay 
> as generic as possible.
> 
> Unless I am confused, the mime type isn't a property of the file it is a 
> property of the data.

For such cache to be generic it should definately support storing 
the mime type in addition to data. For example, if data looks like

"What is <em>this</em> thing?"

how is a computer program (or even a human) going to figure out if 
correct mime type is

a) text/plain
b) application/xhtml+xml
c) application/x-xml-fragment
d) other, what?

Notice that the above example isn't a valid HTML, XHTML or XML 
document. In addition, if you decide text/plain you should be 
somehow able to decipher the correct character set! Notice that you 
cannot know if the above fragment is *supposed* to be a plain text 
example string inside an article about XHTML (in which case it 
should be run through htmlentities() before inserting inside an HTML 
page) if it is indeed a fragment of XHTML code which should be 
inserted as is.

Yes, in general, mime type is property of file instead of a property 
of data. I'd suggest implementing the mime type support for your 
cache and using "application/octet-stream" for already-in-use 
software (just default to that if nothing is provided by caller).

-- 
Mikko



More information about the talk mailing list