Parâmetros

Name of a magic database file, usually something like
/path/to/magic.mime. If not specified, the
MAGIC environment variable is used. If the
environment variable isn't set, then PHP's bundled magic database will
be used.

Passing NULL or an empty string will be equivalent to the default
value.

Valor Retornado

Notas

Aviso

The expected magic database format changed in PHP 5.3.11 and 5.4.1.
Due to this, the internal magic database was upgraded. This mostly effects
code where an external magic database is used: reading an older magic file
will now fail.
Also, some textual representations of the mime types has changed, for
instance for PHP would be "PHP script, ASCII text" instead of "PHP script
text" returned.

Nota:

Generally, using the bundled magic database (by leaving
magic_file and the MAGIC
environment variables unset) is the best course of action unless you
specifically need a custom magic database.

After reading former notes, I wasn't able to load my magic database: 'magic.mime' file (donwloaded from GnuWin32 project, zipped with the binary files v4.21). I always got an invalid $finfo object or finfo_open(...) returned FALSE.

In order to be able to load the 'magic.mime' file, Fileinfo library (bundled in PHP5.2.5) also requires 'magic' file.

The current version (1.04) doesnt support a different mime.magic database than the server default.

(the documentation is thus not correct)Ubuntu default location is '/usr/share/file/magic'. In order for the examples to work all finfo_open()-commands must be issued with the extra location accordingly:<?php$file = "/path/to/file.jpg";$handle = finfo_open(FILEINFO_MIME, '/usr/share/file/magic');$mime_type = finfo_file($handle,$file);?>

On Windows systems people might find that this always returns "application/x-dpkg".There are 2 ways of solving this problem:1. Get the mime-magic database file from GnuWin32 at <http://sourceforge.net/projects/gnuwin32/>2. You can manually "fix" the mime-magic file by editing it and escaping all lines starting with !, thus changing each one to \!