From: "Robert P. J. Day" on

i've perused the general PHP site and the PEAR site, and i haven't
found anything that will let me determine the mime type of a simple
blob of bytes. everything seems to be based off of the data being in
a *file*. in my case, it's not in a file, it's simply a stream of
bytes in a variable, and i'd rather not have to write all that data to
a file just to identify its mime type.

surely there's something that will tell me the mime type of a string
of bytes, no?

rday
--

========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
========================================================================
From: Michael Gauthier on
On Fri, 2010-03-19 at 14:08 -0400, Robert P. J. Day wrote:
> i've perused the general PHP site and the PEAR site, and i haven't
> found anything that will let me determine the mime type of a simple
> blob of bytes. everything seems to be based off of the data being in
> a *file*. in my case, it's not in a file, it's simply a stream of
> bytes in a variable, and i'd rather not have to write all that data to
> a file just to identify its mime type.
>
> surely there's something that will tell me the mime type of a string
> of bytes, no?
>

Hi Robert,

What you could do here is use the data:// string wrapper that's
built-into PHP5 (http://www.php.net/manual/en/wrappers.data.php). That
way, you can treat a string as a file resource. It's a bit of a hack,
but it should work.

Alternatively, opening a feature request against the fileinfo extension
in PHP core would be a good idea.

Cheers,


Mike

From: "Daniel O'Connor" on
>
> Alternatively, opening a feature request against the fileinfo extension
> in PHP core would be a good idea.
>
>
> Oops, I forgot to post this back to the list

http://au.php.net/manual/en/function.finfo-buffer.php

DING!