|
Posted by comp.lang.php on 07/18/07 13:20
[PHP]
<pre>
if (!function_exists('mime_content_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_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);
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);
}
}
}
</pre>
[/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_fileinfo.dll
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:
echo finfo_file(finfo_open(FILEINFO_MIME, 'C:/wamp/php/extras/mime'),
'C:/images/blah.jpg');
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_type()
otherwise,
even though it's deprecated.
Thanks
Phil
Navigation:
[Reply to this message]
|