From a8b6807cf7c99288f91c97669116b27f4fdd4845 Mon Sep 17 00:00:00 2001 From: Michael Joseph Date: Wed, 19 Mar 2003 14:10:22 +0000 Subject: [PATCH] set mime type by extension first, and then consult upload information --- lib/documentmanagement/PhysicalDocumentManager.inc | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/documentmanagement/PhysicalDocumentManager.inc b/lib/documentmanagement/PhysicalDocumentManager.inc index 772749a..32052b5 100644 --- a/lib/documentmanagement/PhysicalDocumentManager.inc +++ b/lib/documentmanagement/PhysicalDocumentManager.inc @@ -178,7 +178,7 @@ class PhysicalDocumentManager { */ function & createDocumentFromUploadedFile($aFileArray, $iFolderID) { //get the uploaded document information and put it into a document object - $oDocument = & new Document($aFileArray['name'], $aFileArray['name'], $aFileArray['size'], $_SESSION["userID"], PhysicalDocumentManager::getMimeTypeID($aFileArray['type']), $iFolderID); + $oDocument = & new Document($aFileArray['name'], $aFileArray['name'], $aFileArray['size'], $_SESSION["userID"], PhysicalDocumentManager::getMimeTypeID($aFileArray['type'], $aFileArray['name']), $iFolderID); return $oDocument; } @@ -189,21 +189,30 @@ class PhysicalDocumentManager { * * @return int mime type primary key if found, else default mime type primary key (text/plain) */ - function getMimeTypeID($sName) { + function getMimeTypeID($sMimeType, $sFileName) { global $default; $sql = $default->db; - //get the mime type - if (isset($sName)) { - $sql->query("SELECT id FROM " . $default->owl_mime_table . " WHERE mimetypes = '$sName'"); + + // check by file extension + $sExtension = strtolower(substr($sFileName, strpos($sFileName, ".")+1, strlen($sFileName) - strpos($sFileName, "."))); + $sql->query("SELECT id FROM " . $default->owl_mime_table . " WHERE LOWER(filetypes) = '$sExtension'"); + if ($sql->next_record()) { + return $sql->f("id"); + } + + //get the mime type + if (isset($sMimeType)) { + $sql->query("SELECT id FROM " . $default->owl_mime_table . " WHERE mimetypes = '$sMimeType'"); if ($sql->next_record()) { //get the mime type id return $sql->f("id"); } } + //otherwise return the default mime type return PhysicalDocumentManager::getDefaultMimeTypeID(); } - + /** * Get the default mime type, which is text/plain * -- libgit2 0.21.4