php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57601 Fileinfo problem with magic files.
Submitted: 2007-03-30 09:38 UTC Modified: 2016-11-24 14:57 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: dario dot borreguero at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.1 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2007-03-30 09:38 UTC] dario dot borreguero at gmail dot com
Description:
------------
After reading several bugs that were set to "Bogus". I believe they should be taken into account:
http://pecl.php.net/bugs/bug.php?id=7391
http://pecl.php.net/bugs/bug.php?id=7555
http://pecl.php.net/bugs/bug.php?id=9166

I've installed this package as an extra, as a result my php.ini file has been modified, inserting the following lines:
[PHP_FILEINFO]
extension=php_fileinfo.dll

After that, I've tried to get the MIME type from a file, using the following code:
$finfo = finfo_open(FILEINFO_MIME);
echo finfo_file($finfo, 'D:\Downloads\test.txt') . "\n";
finfo_close($finfo);

But it has always returned the error:
finfo_open()[function.finfo_open]: Failed to load magic database at '(null)'.

After reading carefully the documentation I realised that it needs another parameter with the name of a magic database file.
http://es2.php.net/manual/en/ref.fileinfo.php

But I could not find any magic file. So I decided to install PECL package Mymetype. After that I got a magic.mime file in the folder c:\php\extras. I thought I could use that file with Fileinfo functions, so I modified the code:
// Extension .mime is automatically added as it is told in
// Bug #7555 and #7391.
$finfo = finfo_open(FILEINFO_MIME, 'c:\php\extras\magic');
echo finfo_file($finfo, 'D:\Downloads\test.txt') . "\n";
finfo_close($finfo);

but I always got the same result:
application/x-dpkg

As it is described in bug #9166, because of the problems with '!' characters. Then, I modified that magic database file escaping that characters (using backslashes) and it seemed to work. But there were a lot more special characters like those and others.

For that reason I dived into that problem and I found more help at the comments added in http://es2.php.net/manual/en/function.finfo-open.php. I just downloaded the files at
http://sourceforge.net/project/showfiles.php?group_id=23617&package_id=18878

As it is said in the links of EvilPuppetMaster's comment. After extracting the files I found a magic.mime file. I used that file and it now works pretty fine!!

In conclusion, Fileinfo PECL package installation should be modified in order to attach a magic.mime file, as it is done in Mimetype PECL package.

Sorry for the length of my explanation, but I've tried to sum up everything I've done to resolve my problem and to keep it clear for future problems.

Dario.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-24 14:57 UTC] ab@php.net
-Status: Open +Status: Not a bug -Package: Fileinfo +Package: *General Issues
 [2016-11-24 14:57 UTC] ab@php.net
This is now in the core.

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 17:01:30 2024 UTC