get('magicDatabase', '/usr/share/file/magic'); $res = finfo_open(FILEINFO_MIME, $magicDatabase); $sType = finfo_file($res, $sFileName); } if (!$sType) { if (file_exists('/usr/bin/file')) { $aCmd = array('/usr/bin/file', '-bi', $sFileName); $sCmd = KTUtil::safeShellString($aCmd); $sPossibleType = @exec($sCmd); if (preg_match('#^[^/]+/[^/*]+$#', $sPossibleType)) { $sType = $sPossibleType; } } } if ($sType) { return preg_replace('/;.*$/', '', $sType); } return null; } function getIconPath($iMimeTypeId) { $cached = KTUtil::arrayGet($GLOBALS['_KT_icon_path_cache'], $iMimeTypeId); if (!empty($cached)) { return $cached; } $GLOBALS['_KT_icon_path_cache'][$iMimeTypeId] = KTMime::_getIconPath($iMimeTypeId); return $GLOBALS['_KT_icon_path_cache'][$iMimeTypeId]; } function _getIconPath($iMimeTypeId) { $sQuery = 'SELECT icon_path FROM mime_types WHERE id = ?'; $res = DBUtil::getOneResult(array($sQuery, array($iMimeTypeId))); if ($res['icon_path'] !== null) { return $res['icon_path']; } else { return 'unspecified_type'; } } function getAllMimeTypes($sAdditional = '') { $sTable = KTUtil::getTableName('mimetypes'); $aQuery = array("SELECT id, mimetypes FROM " . $sTable . ' ' .$sAdditional, array()); $res = DBUtil::getResultArray($aQuery); return $res; } /** * Strip all but the extension from a file. For instance, input of * 'foo.tif' would return 'tif'. * * @param string filename * @return string extension for given file, without filename itself */ function stripAllButExtension($sFileName) { return strtolower(substr($sFileName, strrpos($sFileName, ".")+1, strlen($sFileName) - strrpos($sFileName, "."))); } } $_KT_icon_path_cache = array();