views:

1006

answers:

3

I know mime_content_type() is deprecated, but it seemed to me the alternative is worse at the moment. Finfo seems to require adding files and changing ini directions on windows; I don't want to require this for the script I am making.

I need to find the mimetype of files, but when calling mime_content_type($filename) on windows it fails. mime_magic.magicfile points to the correct file, but when enabling mime_magic.debug in the ini file, I get this error message:

Warning: mime_content_type()[http://www.php.net/mime_magic]: mime_magic not initialized in C:\xampp\htdocs\test.php on line 2

I am not sure if that is a problem or if it still happens when I disable the debugging and it just doesn't tell me.

I checked, and extension=php_mime_magic.dll is enabled in the ini file and httpd.conf specifies

LoadModule mime_module modules/mod_mime.so
#LoadModule mime_magic_module modules/mod_mime_magic.so

I am using XAMPP 1.6.5.

+1  A: 

This may be related to this bug report. Do you have any errors in your error log when you call the script along the lines of 'FOO' is not a valid mimetype, entry skipped?

Unfortunately the final response in that particular thread was to go ahead and use Fileinfo..

Reading through another thread describing the same problem - when you turned on debug, did you set it to "On" or 1? Shouldn't make a difference, but in the thread linked above that seems like part of the solution in that case.


I am not sure if that is a problem or if it still happens when I disable the debugging and it just doesn't tell me.

What are you getting when you echo out the value of mime_content_type with debugging turned off?

ConroyP
I couldn't get it to work with any proposed solutions posted in the thread, and the original poster also gave up. Then again, I couldn't get it to work with Fileinfo either :-(
RobbieGee
A: 

Finfo seems to require adding files and changing ini directions on windows; I don't want to require this for the script I am making.

Have you tried finfo_buffer? That allows you to use the file as a string, so you could do:

$finfo = new finfo;
$filename = $_GET['filename'];
var_dump($finfo->buffer(file_get_contents($filename)));

Also an issue from that bug report was that the mime database was out of date - have you tried with a different copy?

Ross
A: 

Fileinfo can be a trick to get going on Windows. Instructions here: http://forums.zend.com/viewtopic.php?f=8&t=337#p14681

Jonathon Hill