NYCPHP Meetup

NYPHP.org

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

Scott Mattocks scott at crisscott.com
Wed Jan 25 11:15:41 EST 2006


Thanks Chris and Anderw.

I found the answer I was looking for in the fileinfo PECL extension 
(http://pecl.php.net/package/fileinfo). With this extension I can do the 
following:

// Get the image data (see previous message for psuedo code)
$fi = finfo_open(FILEINFO_MIME);
$contentType = finfo_buffer($fi, $image);
// Set the headers and output the message.

I'll probably end up doing a check to see if the extension is loaded and 
if not use method 1 that you mentioned.

Thanks,
Scott

Andrew Yochum wrote:
> On Wed, Jan 25, 2006 at 10:37:42AM -0500, Scott Mattocks wrote:
> 
> That said, I believe you can make what you want happen a few ways:
> 1. Write the file to a temp file:
>     $out = fopen($filename = tempnam("/tmp", 'mime'), 'w');
>     fwrite($out, $file_contents);
>     fclose($out);
>     $mimetype = mime_content_type($filename);
>     unlink($filename);



More information about the talk mailing list