Fileinfo always returns wrong MIME type

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

if (!function_exists('mime_content_type_fileinfo')) {
  * Will use {@link FileInfo} functions
provided within {@link PECL} bundle to return mime
  * @param string $file
  * @return string $mime_type
  * @see mime_content_type
 function &mime_content_type_fileinfo($file) {
    global $windowsMagicMimePath, $mimeTypeFilePath;
    $mimePath = (($_ENV['windir'] || $_SERVER['windir']) &&
$windowsMagicMimePath) ? $windowsMagicMimePath : $mimeTypeFilePath;
    if ($_ENV['windir'] || $_SERVER['windir']) $mimePath = preg_replace('/
\.mime$/i', '', $mimePath);
    print_r("mimePath = $mimePath\n");
    if (class_exists('FileInfo')) {
     $finfo =& new FileInfo(FILEINFO_MIME, $mimePath);
     if (is_object($finfo)) {
      return $finfo->file($file);
     } else if (function_exists('finfo_open')) {
      $mime = finfo_file(finfo_open(FILEINFO_MIME, $mimePath), $file);
      if ($mime) return mime; else return mime_content_type($file);
     } else {
      return mime_content_type($file);
    } else if (function_exists('finfo_open')) {
     $mime = finfo_file(finfo_open(FILEINFO_MIME, $mimePath), $file);
     if ($mime) return $mime; else return mime_content_type($file);
    } else {
     return mime_content_type($file);

WAMP 5.0, WinXP, PHP 5.2.0, Apache 2.0

Whenever I run this function within SAPI PHP, though I have added this
line to php.ini:


And restarted web services, class_exists('FileInfo') is always false,
furthermore, function_exists('finfo_open') is also always false

That I absolutely do not get

However, in CLI PHP, class_exists('FileInfo') is still false, however
function_exists('finfo_open') comes back true this time

But, if I try to use this line on a JPEG image:

[PHP]echo finfo_file(finfo_open(FILEINFO_MIME, 'C:/wamp/php/extras/
mime'), 'C:/images/blah.jpg');[/PHP]

I wind up instead of 'image/jpeg', this instead:


Anyone who knows how to use FileInfo is welcome to play around with
the function to make it fit, but it defaults to mime_content_type()
otherwise, even though it's deprecated.


Site Timeline