summaryrefslogtreecommitdiff
path: root/src/lib/Mime.class.php
blob: 40562b44d49fa17920f827199fce7e3152d96fbf (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
<?php

class Mime {
	public static $mimes = array(
		'csv'	=>	array('text/x-comma-separated-values',
				      'text/comma-separated-values',
				      'application/octet-stream',
				      'application/vnd.ms-excel',
				      'text/x-csv', 'text/csv', 'application/csv',
				      'application/excel', 'application/vnd.msexcel'),
		'xhtml'	=>	array('text/html', 'application/xhtml+xml'),
		'bmp'	=>	'image/bmp',
		'gif'	=>	'image/gif',
		'jpeg'	=>	array('image/jpeg', 'image/pjpeg'),
		'jpg'	=>	array('image/jpeg', 'image/pjpeg'),
		'jpe'	=>	array('image/jpeg', 'image/pjpeg'),
		'png'	=>	array('image/png',  'image/x-png'),
		'tiff'	=>	'image/tiff',
		'tif'	=>	'image/tiff',
		'css'	=>	'text/css',
		'html'	=>	'text/html',
		'htm'	=>	'text/html',
		'txt'	=>	'text/plain',
		'json'	=>	array('application/json', 'text/json')
		);
	
	public static function ext2mime($ext) {
		$mimes = self::$mimes;
		$mime = $mimes[$ext];
		if (!is_array($mime)) $mime = array($mime);
		return $mime;
	}
	public static function mime2ext($my_mime) {
		$ret = array();
		foreach (self::mimes as $ext => $mime) {
			if (is_array($mime)) {
				$match = in_array($my_mime, $mime);
			} else {
				$match = $my_mime==$mime;
			}
			if ($match) $ret[] = $ext;
		}
		return $ret;
	}
}