473,563 Members | 2,897 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fileinfo inconsistent, returning wrong MIME type

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

echo finfo_file(finf o_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_ty pe()
otherwise,
even though it's deprecated.

Thanks
Phil

Jul 18 '07 #1
1 3524
On Jul 18, 9:20 am, "comp.lang. php" <phillip.s.pow. ..@gmail.com>
wrote:
[PHP]
<pre>
if (!function_exis ts('mime_conten t_type_fileinfo ')) {
/**
* Will use {@linkhttp://us2.php.net/fileinfoFileInf o} functions
provided within {@linkhttp://pecl.php.netPEC L} 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);
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);
}
}}

</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_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:

echo finfo_file(finf o_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_ty pe()
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.dl l 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.dl l within PHP's php.ini
2) Have php_fileinfo.dl l within Window's php.ini
3) Have php_fileinfo.dl l 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
6528
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 attempted to edit the value of the System.IO.FileInfo properties. Is there an existing UITypeEditor that will do this type of thing, or will I need to...
5
19570
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 having a problem in the calling program. I searched online and found suggestions that I return an Array instead so I modified my code (below) to return...
27
1874
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. The compiler knows how big arr is, so why the difference - esp. as it would be v.useful if sizeof(arr) worked in someFunction as it does in main - so...
23
5894
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 on most machines, on some machines I experience this problem: When loading the page a window pops up that asks if I want to open the document...
20
2588
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 when you give it 2 or more words, but when there's only 1 word the results vary depending on whether it's on Windows or Linux: under MSVC it displays...
35
2312
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 beginning! Very illogical! And hard to remember. Now this can quite easily be corrected by macros, for example: #include <stdio.h> #define...
0
1776
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 type * * @param string $file * @return string $mime_type * @see mime_content_type */
4
3553
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 = "C:\xampp\htdocs\app\webroot\pics\file.jpg"; $handle = finfo_open(FILEINFO_COMPRESS,'c:/magic');// FILEINFO_COMPRESS,"c:/magic"); if (!$handle) { echo "Opening fileinfo...
6
6487
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 the lines mime_magic.debug = Off and mime_magic.magicfile = "C:\Program Files\PHP\extras\magic.mime". Now my phpinfo() says fileinfo support is...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6255
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
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 we have to send another system
0
924
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.