Commit a8b6807cf7c99288f91c97669116b27f4fdd4845

Authored by Michael Joseph
1 parent 69dc3d57

set mime type by extension first, and then consult upload information


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1618 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/PhysicalDocumentManager.inc
@@ -178,7 +178,7 @@ class PhysicalDocumentManager { @@ -178,7 +178,7 @@ class PhysicalDocumentManager {
178 */ 178 */
179 function & createDocumentFromUploadedFile($aFileArray, $iFolderID) { 179 function & createDocumentFromUploadedFile($aFileArray, $iFolderID) {
180 //get the uploaded document information and put it into a document object 180 //get the uploaded document information and put it into a document object
181 - $oDocument = & new Document($aFileArray['name'], $aFileArray['name'], $aFileArray['size'], $_SESSION["userID"], PhysicalDocumentManager::getMimeTypeID($aFileArray['type']), $iFolderID); 181 + $oDocument = & new Document($aFileArray['name'], $aFileArray['name'], $aFileArray['size'], $_SESSION["userID"], PhysicalDocumentManager::getMimeTypeID($aFileArray['type'], $aFileArray['name']), $iFolderID);
182 return $oDocument; 182 return $oDocument;
183 } 183 }
184 184
@@ -189,21 +189,30 @@ class PhysicalDocumentManager { @@ -189,21 +189,30 @@ class PhysicalDocumentManager {
189 * 189 *
190 * @return int mime type primary key if found, else default mime type primary key (text/plain) 190 * @return int mime type primary key if found, else default mime type primary key (text/plain)
191 */ 191 */
192 - function getMimeTypeID($sName) { 192 + function getMimeTypeID($sMimeType, $sFileName) {
193 global $default; 193 global $default;
194 $sql = $default->db; 194 $sql = $default->db;
195 - //get the mime type  
196 - if (isset($sName)) {  
197 - $sql->query("SELECT id FROM " . $default->owl_mime_table . " WHERE mimetypes = '$sName'"); 195 +
  196 + // check by file extension
  197 + $sExtension = strtolower(substr($sFileName, strpos($sFileName, ".")+1, strlen($sFileName) - strpos($sFileName, ".")));
  198 + $sql->query("SELECT id FROM " . $default->owl_mime_table . " WHERE LOWER(filetypes) = '$sExtension'");
  199 + if ($sql->next_record()) {
  200 + return $sql->f("id");
  201 + }
  202 +
  203 + //get the mime type
  204 + if (isset($sMimeType)) {
  205 + $sql->query("SELECT id FROM " . $default->owl_mime_table . " WHERE mimetypes = '$sMimeType'");
198 if ($sql->next_record()) { 206 if ($sql->next_record()) {
199 //get the mime type id 207 //get the mime type id
200 return $sql->f("id"); 208 return $sql->f("id");
201 } 209 }
202 } 210 }
  211 +
203 //otherwise return the default mime type 212 //otherwise return the default mime type
204 return PhysicalDocumentManager::getDefaultMimeTypeID(); 213 return PhysicalDocumentManager::getDefaultMimeTypeID();
205 } 214 }
206 - 215 +
207 /** 216 /**
208 * Get the default mime type, which is text/plain 217 * Get the default mime type, which is text/plain
209 * 218 *