You are here: Re: Fileinfo inconsistent, returning wrong MIME type « All PHP « IT news, forums, messages
Re: Fileinfo inconsistent, returning wrong MIME type

Posted by comp.lang.php on 07/30/07 13:00

On Jul 18, 9:20 am, "comp.lang.php" <phillip.s.pow...@gmail.com>
wrote:
> [PHP]
> <pre>
> if (!function_exists('mime_content_type_fileinfo')) {
> /**
> * Will use {@linkhttp://us2.php.net/fileinfoFileInfo} functions
> provided within {@linkhttp://pecl.php.netPECL} 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

*update*

Ready for this one?

I did what was suggested: putting in "path" as both user and system
environmental variable, rebooted my machine.. NO PECL

Then I added the path to the PHP executable to both user and system
"path"
environmental variables, rebooted my machine.. STILL NO PECL

Then I finally decided to just "wing it". I tried everything my
imagination could deliver to me..

When I got to the part where I needed to add lines to wampserver.ini
to
recognize php_fileinfo.dll with the "on" option, I got PECL!

In fact, I found that through backward engineering the problem, that
there
was only one solution:

1) Have php_fileinfo.dll within PHP's php.ini
2) Have php_fileinfo.dll within Window's php.ini
3) Have php_fileinfo.dll within wampserver.ini

If any of these steps are not included, alongside the obvious web
services
restart, then PECL is not recognized.

In fact, I was able to get full PECL recognition even after I took out
the
"path" user defined environmental variable AND even after removing
the
paths to the PHP executable from the "path" system defined
environmental
variable!

Thanx all!
Phil

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация