From acdc38fffbe0ed61f485b8a8da9ae0f39ccafcb5 Mon Sep 17 00:00:00 2001 From: Conrad Vermeulen Date: Wed, 1 Oct 2008 10:12:04 +0000 Subject: [PATCH] KTC-417 "A license file (once uploaded) is seen as a binary file" Fixed. --- lib/mime.inc.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/mime.inc.php b/lib/mime.inc.php index 9345d31..fb44f32 100644 --- a/lib/mime.inc.php +++ b/lib/mime.inc.php @@ -154,13 +154,35 @@ class KTMime { */ function getMimeTypeFromFile($sFileName) { if (extension_loaded('fileinfo')) { - $oKTConfig =& KTConfig::getSingleton(); - $magicDatabase = $oKTConfig->get('magicDatabase', '/usr/share/file/magic'); - $res = finfo_open(FILEINFO_MIME, $magicDatabase); - $sType = finfo_file($res, $sFileName); + // NOTE: fileinfo doesn't like all magic files. ensure it is pointing to a compatible one if it does not work. + + // first check the path in the stack + $defaultMagicPath = KT_DIR . '/../php/extras/magic'; + $defaultMagicPath = realpath($defaultMagicPath); + + // if not available, attempt path from config + if ($defaultMagicPath === false) { + $oKTConfig =& KTConfig::getSingleton(); + $defaultMagicPath = $oKTConfig->get('magicDatabase'); + + if (!file_exists($defaultMagicPath)) { + $defaultMagicPath = false; + } + } + + // attempt file info if magic file is resolved + if ($defaultMagicPath) { + $res = @finfo_open(FILEINFO_MIME, $defaultMagicPath); + $sType = @finfo_file($res, $sFileName); + + // saw mention that finfo_file() can return empty string under windows + if (empty($sType)) { + $sType = false; + } + } } - if (!$sType) { + if (!$sType && OS_UNIX) { if (file_exists('/usr/bin/file')) { $aCmd = array('/usr/bin/file', '-bi', $sFileName); $sCmd = KTUtil::safeShellString($aCmd); -- libgit2 0.21.4