Fileinfo always returns wrong MIME type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • comp.lang.php

    Fileinfo always returns wrong MIME type

    [PHP]
    if (!function_exis ts('mime_conten t_type_fileinfo ')) {
    /**
    * Will use {@link http://us2.php.net/fileinfo FileInfo} functions
    provided within {@link http://pecl.php.net PECL} bundle to return mime
    type
    *
    * @param string $file
    * @return string $mime_type
    * @see mime_content_ty pe
    */
    function &mime_content_t ype_fileinfo($f ile) {
    global $windowsMagicMi mePath, $mimeTypeFilePa th;
    $mimePath = (($_ENV['windir'] || $_SERVER['windir']) &&
    $windowsMagicMi mePath) ? $windowsMagicMi mePath : $mimeTypeFilePa th;
    if ($_ENV['windir'] || $_SERVER['windir']) $mimePath = preg_replace('/
    \.mime$/i', '', $mimePath);
    print_r("mimePa th = $mimePath\n");
    if (class_exists(' FileInfo')) {
    $finfo =& new FileInfo(FILEIN FO_MIME, $mimePath);
    if (is_object($fin fo)) {
    return $finfo->file($file);
    } else if (function_exist s('finfo_open') ) {
    $mime = finfo_file(finf o_open(FILEINFO _MIME, $mimePath), $file);
    if ($mime) return mime; else return mime_content_ty pe($file);
    } else {
    return mime_content_ty pe($file);
    }
    } else if (function_exist s('finfo_open') ) {
    $mime = finfo_file(finf o_open(FILEINFO _MIME, $mimePath), $file);
    if ($mime) return $mime; else return mime_content_ty pe($file);
    } else {
    return mime_content_ty pe($file);
    }
    }
    }
    [/PHP]

    Environment:
    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:

    extension=php_f ileinfo.dll
    And restarted web services, class_exists('F ileInfo') is always false,
    furthermore, function_exists ('finfo_open') is also always false

    That I absolutely do not get

    However, in CLI PHP, class_exists('F ileInfo') 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(finf o_open(FILEINFO _MIME, 'C:/wamp/php/extras/
    mime'), 'C:/images/blah.jpg');[/PHP]

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

    application/x-dpkg\015
    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_ty pe()
    otherwise, even though it's deprecated.

    Thanks
    Phil

Working...