473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Fileinfo inconsistent, returning wrong MIME type

[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

Jul 18 '07 #1
1 3516
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

Jul 30 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lance | last post by:
I want to expose properties of a class to a user via a PropertyGrid class. Some of the properties are of type System.IO.FileInfo. Ideally, an OpenFileDialog window would appear when the user...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
27
by: jimbo | last post by:
Could someone comment on this code please. 1. Are the comments in it correct? 2. Why does sizeof(arr) not work consistently in C? In someFunction() sizeof(arr) means sizeof(&arr) in main. ...
23
by: Peter | last post by:
I have a problem with a page show_image.asp that returns a jpg image under Windows XP Pro SP2. The page sets content type as: Response.ContentType = "image/jpg" While this works perfectly fine...
20
by: Francine.Neary | last post by:
I am learning C, having fun with strings & pointers at the moment! The following program is my solution to an exercise to take an input, strip the first word, and output the rest. It works fine...
35
by: Francine.Neary | last post by:
I'm finding it really hard to keep some of these things straight... For example, fputs is to puts as fprintf is to printf, except that fputs has the file handle at the end and fprintf at the...
0
by: comp.lang.php | last post by:
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...
4
by: bob | last post by:
I am having trouble getting the PHP PECL fileinfo component to work. I am using Cakephp 1.2, XAMPP in WIndows Vista environment. I have the following code: $file =...
6
by: tinman77 | last post by:
Hello, I'm having a terrible time using the functions finfo_open and finfo_file. I'm using PHP 5 on IIS 5.1 and Windows XP. I have enabled php_mime_magic.dll and php_fileinfo.dll and also added...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.