summaryrefslogtreecommitdiff
path: root/forum/utils/mimetypes.php
diff options
context:
space:
mode:
Diffstat (limited to 'forum/utils/mimetypes.php')
-rw-r--r--forum/utils/mimetypes.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/forum/utils/mimetypes.php b/forum/utils/mimetypes.php
new file mode 100644
index 0000000..f9ecfea
--- /dev/null
+++ b/forum/utils/mimetypes.php
@@ -0,0 +1,50 @@
+<?php
+
+class MimeType {
+ public $name;
+ public $exts = array();
+ public $show;
+
+ public function MimeType($name, $exts, $show)
+ {
+ $this->name = $name;
+ $this->exts = $exts;
+ $this->show = $show;
+ }
+};
+
+
+$DEFAULT_MIME_TYPE = new MimeType("application/octet-stream", array(), false);
+
+// Know mimetypes
+$MIME_TYPES = array(new MimeType("image/jpeg",array("jpg","jpeg","jpe"),true),
+ new MimeType("image/gif",array("gif"),true),
+ new MimeType("image/png",array("png"),true),
+ new MimeType("audio/mpeg",array("mp3","mpga","mpega","mp2","m4a"),false),
+ new MimeType("application/ogg",array("ogg"),false),
+ new MimeType("application/pdf",array("pdf"),false),
+ new MimeType("application/msword",array("doc"),false),
+ new MimeType("text/plain", array("asc","txt","text","diff","pot"), true)
+ );
+
+
+// Get file extension.
+function extension($file) {
+ $fileExp = explode('.', $file); // make array off the periods
+ $filetype = $fileExp[count($fileExp) -1]; // file extension will be last index in array, -1 for 0-based indexes
+ return strtolower($filetype);
+}
+
+function getMimeType($file)
+{
+ global $DEFAULT_MIME_TYPE;
+ global $MIME_TYPES;
+
+ $ext = extension($file);
+ foreach($MIME_TYPES as $m) {
+ foreach($m->exts as $e) if($e == $ext) return $m;
+ }
+ return $DEFAULT_MIME_TYPE;
+}
+
+?> \ No newline at end of file