php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57662 environment variable 'MAGIC' is not used
Submitted: 2007-05-10 10:09 UTC Modified: 2013-02-18 00:35 UTC
From: info at adaniels dot nl Assigned:
Status: No Feedback Package: Fileinfo (PECL)
PHP Version: 5.2.1 OS: Linux (Ubuntu)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: info at adaniels dot nl
New email:
PHP Version: OS:

 

 [2007-05-10 10:09 UTC] info at adaniels dot nl
Description:
------------
According to the manual, the environment variable 'MAGIC' will be used as path to the magic file by default. But it looks like this is not the case. Also the documentation states it will use '/usr/share/misc/magic', but in fact it tries multiple files.

Ubuntu places an empty magic file in /etc, in which you may store custom info. But the magic file of the distro is located in '/usr/share/file/magic'. Even though the distro file is in the MAGIC_MIME_LOCATIONS variable as well, the package prefers to use /etc/magic. This is unfortunate.
It seems like the `file` command is able to use multiple magic files, but it looks like the fileinfo extension can only use 1.

-------

From the manual (http://www.php.net/finfo-open):

magic_file

    Name of a magic database file, usually something like /path/to/magic.mime. If not specified, MAGIC environment variable is used. If this variable is not set neither, /usr/share/misc/magic is used. .mime and/or .mgc is added if appropriate. 

Reproduce code:
---------------
<?php
    var_dump(getenv('MAGIC'));

    putenv('MAGIC=/usr/share/file/magic');
    $finfo= new finfo(FILEINFO_NONE);
    
    echo $finfo->file(__FILE__);
?>

Expected result:
----------------
bool(false)
PHP script text

Actual result:
--------------
bool(false)

Warning: finfo::finfo() [function.finfo-finfo]: Failed to load magic database at '/etc/magic'. in /home/arnold/projects/jasny/jasny-explorer/webroot/test.php on line 5

Warning: finfo::file() [function.finfo-file]: The invalid fileinfo object. in /home/arnold/projects/jasny/jasny-explorer/webroot/test.php on line 7


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-02 10:37 UTC] mj@php.net
Works fine for me with the fileinfo extension that ships with 5.3.0-dev.

Can you please try PHP 5.3.0alpha1 from http://downloads.php.net/johannes/?
 [2009-10-07 04:45 UTC] dragos dot rusu at ymail dot com
Can reproduce this under Centos 5.2, PHP 5.2.11, Apache HTTPD 2.2.3 (fileinfo installed with pecl). Check comment here: http://pecl.php.net/bugs/bug.php?id=14600
 [2013-02-18 00:35 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC