/** * check_mime_type * * @param string $fname path to filename * @access public * @return string the mime type of the offended file. * @notes DO NOT use this function for any security related * task (i.e limiting file uploads by type) * it wasn't designed for that purpose but to UI related tasks. */ public static function check_mime_type($fname) { $type = ''; if (extension_loaded('fileinfo') && class_exists('finfo')) { $info = new finfo(FILEINFO_MIME); $type = $info->file($fname); } elseif (function_exists('mime_content_type')) { $type = @mime_content_type($fname); // I hope we don't have to... } elseif (!FlySpray::function_disabled('exec') && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' && php_uname('s') !== 'SunOS') { $type = @exec(sprintf('file -bi %s', escapeshellarg($fname))); } // if wasn't possible to determine , return empty string so // we can use the browser reported mime-type (probably fake) return trim($type); }
/** * check_mime_type * * @param string $fname path to filename * @access public * @return string the mime type of the offended file. * @notes DO NOT use this function for any security related * task (i.e limiting file uploads by type) * it wasn't designed for that purpose but to UI related tasks. */ function check_mime_type($fname) { $type = ''; if (extension_loaded('fileinfo') && class_exists('finfo')) { $info = new finfo(FILEINFO_MIME); $type = $info->file($fname); } elseif (function_exists('mime_content_type')) { $type = @mime_content_type($fname); // I hope we don't have to... } elseif (!FlySpray::function_disabled('exec') && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' && php_uname('s') !== 'SunOS') { include_once 'class.commandexecution.php'; $file = new CommandExecution(); $file->setCmd('file'); $file->bi = $fname; $type = $file->getCmdResult(); } // if wasn't possible to determine , return empty string so // we can use the browser reported mime-type (probably fake) return trim($type); }