Commit acdc38fffbe0ed61f485b8a8da9ae0f39ccafcb5
1 parent
bf7ef94d
KTC-417
"A license file (once uploaded) is seen as a binary file" Fixed. Committed By: Conrad Vermeulen Reviewed By: Megan Watson git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@9434 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
27 additions
and
5 deletions
lib/mime.inc.php
| ... | ... | @@ -154,13 +154,35 @@ class KTMime { |
| 154 | 154 | */ |
| 155 | 155 | function getMimeTypeFromFile($sFileName) { |
| 156 | 156 | if (extension_loaded('fileinfo')) { |
| 157 | - $oKTConfig =& KTConfig::getSingleton(); | |
| 158 | - $magicDatabase = $oKTConfig->get('magicDatabase', '/usr/share/file/magic'); | |
| 159 | - $res = finfo_open(FILEINFO_MIME, $magicDatabase); | |
| 160 | - $sType = finfo_file($res, $sFileName); | |
| 157 | + // NOTE: fileinfo doesn't like all magic files. ensure it is pointing to a compatible one if it does not work. | |
| 158 | + | |
| 159 | + // first check the path in the stack | |
| 160 | + $defaultMagicPath = KT_DIR . '/../php/extras/magic'; | |
| 161 | + $defaultMagicPath = realpath($defaultMagicPath); | |
| 162 | + | |
| 163 | + // if not available, attempt path from config | |
| 164 | + if ($defaultMagicPath === false) { | |
| 165 | + $oKTConfig =& KTConfig::getSingleton(); | |
| 166 | + $defaultMagicPath = $oKTConfig->get('magicDatabase'); | |
| 167 | + | |
| 168 | + if (!file_exists($defaultMagicPath)) { | |
| 169 | + $defaultMagicPath = false; | |
| 170 | + } | |
| 171 | + } | |
| 172 | + | |
| 173 | + // attempt file info if magic file is resolved | |
| 174 | + if ($defaultMagicPath) { | |
| 175 | + $res = @finfo_open(FILEINFO_MIME, $defaultMagicPath); | |
| 176 | + $sType = @finfo_file($res, $sFileName); | |
| 177 | + | |
| 178 | + // saw mention that finfo_file() can return empty string under windows | |
| 179 | + if (empty($sType)) { | |
| 180 | + $sType = false; | |
| 181 | + } | |
| 182 | + } | |
| 161 | 183 | } |
| 162 | 184 | |
| 163 | - if (!$sType) { | |
| 185 | + if (!$sType && OS_UNIX) { | |
| 164 | 186 | if (file_exists('/usr/bin/file')) { |
| 165 | 187 | $aCmd = array('/usr/bin/file', '-bi', $sFileName); |
| 166 | 188 | $sCmd = KTUtil::safeShellString($aCmd); | ... | ... |