yet another mime_magic
| From: | Moriyoshi Koizumi | Date: | Tue, 07 May 2002 18:51:55 +0000 |
| Subject: | yet another mime_magic | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-83800@lists.php.net to get a copy of this message | ||
Hi,
I wrote a PHP extension for magic file based file type determination
though there's already a similar and stable one(mime_magic)...
(Sadly it was too late that I found mime_magic extension in CVS :)
And I still have no idea where is the right place to put this one to...
Now let me explain differences between my humble extension and mime_magic.
+ caching magic database for fast fetching in the next time.
(you can also use this as a tiny persistent storage.)
+ use php streams if it is enabled.
+ capable of listening on the stream.
+ phpizable with both old / new build system
- written from scratch (not taken from Apache's source tree).
- not fully conforming to magic file spec(not a matter for now)
- and some trivial things.
Synopsis:
$fp = fopen( 'test.unknown', 'rb' );
list( $mimetype, $subtype ) = mglookup_stream( $fp );
echo "$mimetype\n";
echo "$subtype\n";
close( $fp );
Functions:
array mglookup_stream( resource $stream, [, string $magic_file_path] );
array mglookup_string( string $buf [, string $magic_file_path] );
INI entries:
mglookup.magic_file_path = path
mglookup.caching = { 0, 1 }
Known bugs:
- namespace polutive sources
- uncontrolable caching behaviour
- not working with socket streams
(Buffered stream might be required if you do with them)
If you are interested, you can download mglookup extension from
http://www.voltex.jp/mglookup/mglookup-dev.tar.gz
I haven't built nor tested this in win32 environment, but I guess
it will work without major changes.
--
Moriyoshi Koizumi