summaryrefslogtreecommitdiff
path: root/forum/utils/mimetypes.php
blob: f9ecfeaf28d2498d7e08d138937b4ec098feac2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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;
}

?>