Re: PECL FileInfo extension, magic not found

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Try using this instead of mime_content_type() (which is depracated)

if (!function_exists('mime_content_type'))
{
   function mime_content_type($file)
   {
     return trim(exec('file -bi ' . escapeshellarg($file)));
   }
}

It will only work on a linux box though

Roland Bu'ulölö wrote:
> 
> 
> Dear all
> 
> I'm having problem with my PECL fileinfo extension. All the methods are
> recognized correctly (finfo_open, finfo_close, finfo_file, etc), but when I
> try to read some file mime type using:
> 
> ----------------------------------------------------------
> $finfo = finfo_open(FILEINFO_MIME);
> $fmime = finfo_file($finfo,$fullFilePath);
> finfo_close($finfo);
> echo "$fmime";
> ----------------------------------------------------------
> 
> I expect a result like
> ----------------------------------------------------------
> image/gif
> ----------------------------------------------------------
> 
> But what I got is this
> ----------------------------------------------------------
> Warning: finfo_open()
> [function.finfo-open<http://cmdb.id.consfin.ge.com/function.finfo-open 
> <http://cmdb.id.consfin.ge.com/function.finfo-open>>]:
> Failed to load magic database at '/usr/share/misc/magic'. in
> /home/httpd/htdocs/test/landem.php on line 2
> 
> Warning: finfo_file(): supplied argument is not a valid file_info resource
> in /home/httpd/htdocs/test/landem.php on line 3
> 
> Warning: finfo_close(): supplied argument is not a valid file_info resource
> in /home/httpd/htdocs/test/landem.php on line 4
> ----------------------------------------------------------
> 
> I've checked the magic file in my system and it has the correct permission
> and it has contents about filetype and the like (I think).
> Please help me, what's wrong with this? Is there any other way around?
> My php --version is:
> -------
> PHP 5.2.3 (cli) (built: Jul 19 2007 14:27:58)
> Copyright (c) 1997-2007 The PHP Group
> Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
> -------
> 
> I've been trying to use mime_content_type() before but php doesn't recognize
> it.
> 
> Thanks is advance.
> 
> -- 
> ~ R.L.B. ~
> 
> [Non-text portions of this message have been removed]
> 
> 

[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux