Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.1

Request #10568 Improvement on using MIME_Type class
Submitted: 2007-03-30 18:40 UTC
From: darizotas Assigned:
Status: Wont fix Package: MIME_Type (version 1.0.0)
PHP Version: 5.2.1 OS: Windows XP SP2
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 36 + 4 = ?

 
 [2007-03-30 18:40 UTC] darizotas (Dario Borreguero)
Description: ------------ I have tried to use MIME_Type class, but I've found two issues: 1- Windows doesn't have 'file' command. Therefore, System_Command class can't be used. 2- mime_content_type is deprecated and the magic.mime file bundled in PHP 5.2.1 release doesn't work properly. So after diving a bit for trying to resolve this issue, I could find a correct magic.mime file at http://sourceforge.net/project/showfiles.php?group_id=23617&package_id=18878 And I wrote a simple class that works with PECL package Fileinfo (it supersedes mime_content_type function): <?php /** Exceptions. */ require_once 'PEAR/Exception.php'; /** Default magic file. */ if (!defined('MIME_TYPE_FILE')) define('MIME_TYPE_FILE', 'extras/magic'); /** * Class based on PECL Fileinfo package that detects MIME * Types. * This class requires a magic file, this file contains all * data needed to detect MIME types from a given file. * Further information on {@link http://es2.php.net/manual/en/function.finfo-open.php} * @package util * @author Dario Borreguero * @version 1.0.0 */ class MIME_Type_Tool { /** * Returns MIME Type from the given file. * Throws an exception whether the file doesn't exist * @param string File to detect the MIME Type. * @return mixed MIME Type or false in case of error. * @throws PEAR_Exception */ public static function detects($fname) { // Checks if it exists. if (!file_exists($fname)) throw new PEAR_Exception('The file '.$fichero.' does not exist.'); // Fileinfo package included. if (function_exists('finfo_open') && function_exists('finfo_file') && function_exists('finfo_close')) { // Loads magic file. $finfo = finfo_open(FILEINFO_MIME, MIME_TYPE_FILE); if (!$finfo && $finfo === false) return false; $type = finfo_file($finfo, $fname); finfo_close($finfo); return $type; } else return false; } } ?> But I found another issue, if the given file is encrypted using Windows encryption mechanism it doesn't work. It shows the message: 'writable, regular file, no read permission' I hope this helps, DArio

Comments

 [2008-07-24 18:07 UTC] ieure (Ian Eure)
At some point, I'll switch to using the newer file ID mechanism, but I think it needs to stay how it is for the time being.