473,499 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fileinfo always returns wrong MIME type

[PHP]
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);
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);
}
}
}
[/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:

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

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
0 1772

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

Similar topics

10
4672
by: comp.lang.php | last post by:
echo mime_content_type('/var/www/html/video/small.mov'); // 1.5mb Quicktime video returns "video/quicktime" echo mime_content_type('/var/www/html/video/huge.mov'); // 10.5mb Quicktime video...
5
1846
by: Gernold Schneider | last post by:
I have a managed code function calling a unmanaged code function which returns a "bool". Obviously the return value is always "true", if i am not running the code in the debugger. If i run the...
5
6890
by: mtv | last post by:
Hi all, I have the following code: ================================ Webservice side: public class MyWS: WebService { private myLib.DataObject curDataObject;
0
1567
by: mjed01 | last post by:
hi, i am trying to implement a web service using php. it should return a complex type, but it is always null. i have the following wsdl: <?xml version="1.0" encoding="utf-8"?> ...
3
2153
by: rn5a | last post by:
To work with files, when should one use the File class & when should one use the FileInfo class? Similarly, to work with directories, when should one use the Directory class & when should one...
1
3522
by: comp.lang.php | last post by:
<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...
5
6133
by: Tom P. | last post by:
I am having the following problem: I create a FileSystemWatcher and wait for events. When the event does happen I refresh a FileSystemInfo list and set properties accordingly (IsFile, IsDir,...
4
3544
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
6479
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
7128
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
7215
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...
1
6892
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
7385
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
294
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.