From 0fb942ec33afc0ca970a028931fa4692582561cb Mon Sep 17 00:00:00 2001 From: kevinjardine Date: Thu, 16 Apr 2009 08:25:21 +0000 Subject: Added file_get_general_file_type() function git-svn-id: https://code.elgg.org/elgg/trunk@3213 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/filestore.php | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'engine/lib/filestore.php') diff --git a/engine/lib/filestore.php b/engine/lib/filestore.php index 67330c4e5..ea96bd5c9 100644 --- a/engine/lib/filestore.php +++ b/engine/lib/filestore.php @@ -879,6 +879,44 @@ return false; } + /** + * Returns an overall file type from the mimetype + * + * @param string $mimetype The MIME type + * @return string The overall type + */ + function file_get_general_file_type($mimetype) { + + switch($mimetype) { + + case "application/msword": + return "document"; + break; + case "application/pdf": + return "document"; + break; + + } + + if (substr_count($mimetype,'text/')) + return "document"; + + if (substr_count($mimetype,'audio/')) + return "audio"; + + if (substr_count($mimetype,'image/')) + return "image"; + + if (substr_count($mimetype,'video/')) + return "video"; + + if (substr_count($mimetype,'opendocument')) + return "document"; + + return "general"; + + } + function file_handle_upload($prefix,$subtype,$plugin) { $desc = get_input("description"); $tags = get_input("tags"); @@ -965,7 +1003,7 @@ // Save tags $file->tags = $tags; - $file->simpletype = get_general_file_type($uploaded['type']); + $file->simpletype = file_get_general_file_type($uploaded['type']); $file->folder = $folder; $result = $file->save(); -- cgit v1.2.3