* @version 0.1 * @copyright Copyright 2009, Jeffrey Barke * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License */ class finformation { // vars private $finfo = false; private $const = FILEINFO_MIME; private $debug = false; private $magic = '/usr/share/misc/magic'; public $ready = false; // magic methods public function __construct($const = false, $magic = false, $debug = false) { // set fileinfo constant if ($const) { $this->setConst($const); } // set location of magic database file $this->setMagic($magic); // set debug status if (true === $debug) { ini_set('error_reporting', E_ALL); ini_set('display_errors', 'stdout'); } // make sure we can read magic file if ( is_file($this->getMagic()) ) { // create file info object $this->finfo = new finfo($this->getConst(), $this->getMagic()); $this->ready = true; } } // getters private function getConst() { return $this->const; } private function getMagic() { return $this->magic; } // setters private function setConst($const) { $this->const = $const; } private function setMagic($magic = false) { if ($magic) { $this->magic = $magic; } else { if ($_ENV['MAGIC']) { $this->magic = $_ENV['MAGIC']; } } } // public methods public function close() { unset($this->finfo); return true; } public function file($path, $magic = false) { if ($magic) { $this->setMagic($magic); } return $this->finfo->file($path); } /** * @param string Path to file to test MIME type * @param array Array of allowed MIME types * @return bool True if the MIME type of the file is within the array of allowed types */ public function test($path, $arr) { if (!is_array($arr)) { return false; } if (in_array($this->file($path), $arr)) { return true; } else { return false; } } } ?>