» Programming » PHP » MIME Types

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
 
  //here is a master list:  http://www.w3schools.com/media/media_mimeref.asp
 
 
  //MIME TYPE BITMASKS
  define('MIME_TYPE_ALL',       0xFFFFFFFF);
  define('MIME_TYPE_TEXT',      0x00000001);
  define('MIME_TYPE_HYPERTEXT', 0x00000002);
  define('MIME_TYPE_CSS',       0x00000004);
  define('MIME_TYPE_JS',        0x00000008);
  define('MIME_TYPE_CODE',      0x00000080);
  define('MIME_TYPE_WEB_TEXT',  0x0000000F);
  define('MIME_TYPE_ALL_TEXT',  0x000000FF);
  define('MIME_TYPE_XML',       0x00000100);
  define('MIME_TYPE_RSS',       0x00000200);
  define('MIME_TYPE_XHTML',     0x00000400);
  define('MIME_TYPE_DOC_XML',   0x00000800);
  define('MIME_TYPE_ALL_XML',   0x00000F00);
  define('MIME_TYPE_FLASH',     0x00001000);
  define('MIME_TYPE_ALL_MISC',  0x000FF000);
  define('MIME_TYPE_JPEG',      0x00100000);
  define('MIME_TYPE_GIF',       0x00200000);
  define('MIME_TYPE_PNG',       0x00400000);
  define('MIME_TYPE_VRML',      0x00800000);
  define('MIME_TYPE_BMP',       0x01000000);
  define('MIME_TYPE_TIFF',      0x02000000);
  define('MIME_TYPE_ICO',       0x04000000);
  define('MIME_TYPE_WEB_IMAGE', 0x00F00000);
  define('MIME_TYPE_ALL_IMAGE', 0x7FF00000);
  define('MIME_TYPE_BINARY',    0x80000000);
 
 
 
  function get_file_extensions($format=MIME_TYPE_ALL) {
    $file_extensions = array();
 
    if ($format === false) $format = MIME_TYPE_ALL;
 
    if ( ($format & MIME_TYPE_HYPERTEXT) || ($format & MIME_TYPE_XHTML) ) {
      $file_extensions['xhtml']   = 'text/xhtml';
    }
 
    if ($format & MIME_TYPE_HYPERTEXT) {
      $file_extensions['htm']     = 'text/htm';
      $file_extensions['html']    = 'text/html';
      $file_extensions['sht']     = 'text/html';
      $file_extensions['shtm']    = 'text/html';
      $file_extensions['shtml']   = 'text/html';
      $file_extensions['stm']     = 'text/html';
      $file_extensions['wap']     = 'text/html';
    }
 
    if ($format & MIME_TYPE_CSS) {
      $file_extensions['css']     = 'text/css';
    }
 
    if ($format & MIME_TYPE_JS) {
      $file_extensions['js']      = 'application/javascript';
    }
 
    if ($format & MIME_TYPE_XML) {
      $file_extensions['xml']     = 'text/xml';
    }
 
    if ($format & MIME_TYPE_TEXT) {
      $file_extensions['txt']     = 'text/plain';
    }
 
    if ($format & MIME_TYPE_RSS) {
      $file_extensions['rss']     = 'application/rss+xml';
    }
 
    if ($format & MIME_TYPE_FLASH) {
      $file_extensions['swf']     = 'application/x-shockwave-flash';
    }
 
    if ($format & MIME_TYPE_CODE) {
      $file_extensions['bas']     = 'text/plain';
      $file_extensions['c']       = 'text/plain';
      $file_extensions['cs']      = 'text/plain';
      $file_extensions['cpp']     = 'text/plain';
      $file_extensions['h']       = 'text/plain';
      $file_extensions['pls']     = 'text/plain';
    }
 
    if (($format & MIME_TYPE_ALL_TEXT) == MIME_TYPE_ALL_TEXT) {
      $file_extensions['uls']     = 'text/iuls';
      $file_extensions['rtx']     = 'text/richtext';
      $file_extensions['sct']     = 'text/scriptlet';
      $file_extensions['tsv']     = 'text/tab-separated-values';
      $file_extensions['htt']     = 'text/webviewhtml';
      $file_extensions['323']     = 'text/h323';
      $file_extensions['htc']     = 'text/x-component';
      $file_extensions['etx']     = 'text/x-setext';
      $file_extensions['vcf']     = 'text/x-vcard';
    }
 
 
 
    //IMAGES
    if ($format & MIME_TYPE_JPEG) {
      $file_extensions['jpe']     = 'image/jpeg';
      $file_extensions['jpg']     = 'image/jpeg';
      $file_extensions['jpeg']    = 'image/jpeg';
    }
 
    if ($format & MIME_TYPE_TIFF) {
      $file_extensions['tif']     = 'image/tiff';
      $file_extensions['tiff']    = 'image/tiff';
    }
 
    if ($format & MIME_TYPE_GIF) {
      $file_extensions['gif']     = 'image/gif';
    }
 
    if ($format & MIME_TYPE_PNG) {
      $file_extensions['png']     = 'image/png';
    }
 
    if ($format & MIME_TYPE_BMP) {
      $file_extensions['bmp']     = 'image/bmp';
    }
 
    if ($format & MIME_TYPE_ICO) {
      $file_extensions['ico']     = 'image/x-icon';
    }
 
    if ($format & MIME_TYPE_VRML) {
      $file_extensions['flr']     = 'x-world/x-vrml';
      $file_extensions['vrml']    = 'x-world/x-vrml';
      $file_extensions['wrl']     = 'x-world/x-vrml';
      $file_extensions['wrz']     = 'x-world/x-vrml';
      $file_extensions['xaf']     = 'x-world/x-vrml';
      $file_extensions['xof']     = 'x-world/x-vrml';
    }
 
    if ( (($format & MIME_TYPE_ALL_IMAGE) == MIME_TYPE_ALL_IMAGE) 
      || (($format & MIME_TYPE_ALL_XML)   == MIME_TYPE_ALL_XML) ) {
      $file_extensions['svg']     = 'image/svg+xml';
    }
 
    if (($format & MIME_TYPE_ALL_IMAGE) == MIME_TYPE_ALL_IMAGE) {
      $file_extensions['ief']     = 'image/ief';
      $file_extensions['cod']     = 'image/cis-cod';
      $file_extensions['jfif']    = 'image/pipeg';
      $file_extensions['pnm']     = 'image/x-portable-anymap';
      $file_extensions['pbm']     = 'image/x-portable-bitmap';
      $file_extensions['pgm']     = 'image/x-portable-graymap';
      $file_extensions['ppm']     = 'image/x-portable-pixmap';
      $file_extensions['ras']     = 'image/x-cmu-raster';
      $file_extensions['rgb']     = 'image/x-rgb';
      $file_extensions['xbm']     = 'image/x-xbitmap';
      $file_extensions['xpm']     = 'image/x-xpixmap';
      $file_extensions['xwd']     = 'image/x-xwindowdump';
    }
 
 
 
    //BINARY FILES
    if ($format & MIME_TYPE_BINARY) {
      $file_extensions['psd']     = 'application/octet-stream';
      $file_extensions['gz']      = 'application/octet-stream';
      $file_extensions['tar']     = 'application/octet-stream';
      $file_extensions['rar']     = 'application/octet-stream';
      $file_extensions['bin']     = 'application/octet-stream';
      $file_extensions['class']   = 'application/octet-stream';
      $file_extensions['dms']     = 'application/octet-stream';
      $file_extensions['exe']     = 'application/octet-stream';
      $file_extensions['lha']     = 'application/octet-stream';
      $file_extensions['lzh']     = 'application/octet-stream';
      $file_extensions['com']     = 'application/octet-stream';
    }
 
 
 
    if ( ($format & MIME_TYPE_ALL) == MIME_TYPE_ALL) {
      $file_extensions['pdf']     = 'application/pdf';
      $file_extensions['zip']     = 'application/zip';
      $file_extensions['rtf']     = 'application/rtf';
      $file_extensions['hlp']     = 'application/winhlp';
 
      $file_extensions['torrent'] = 'application/x-bittorrent';
 
      $file_extensions['doc']     = 'application/msword';
      $file_extensions['dot']     = 'application/msword';
      $file_extensions['xls']     = 'application/vnd.ms-excel';
      $file_extensions['ppt']     = 'application/vnd.ms-powerpoint';
      $file_extensions['xla']     = 'application/vnd.ms-excel';
      $file_extensions['xlc']     = 'application/vnd.ms-excel';
      $file_extensions['xlm']     = 'application/vnd.ms-excel';
      $file_extensions['xlt']     = 'application/vnd.ms-excel';
      $file_extensions['xlw']     = 'application/vnd.ms-excel';
      $file_extensions['msg']     = 'application/vnd.ms-outlook';
      $file_extensions['sst']     = 'application/vnd.ms-pkicertstore';
      $file_extensions['cat']     = 'application/vnd.ms-pkiseccat';
      $file_extensions['stl']     = 'application/vnd.ms-pkistl';
      $file_extensions['pot']     = 'application/vnd.ms-powerpoint';
      $file_extensions['pps']     = 'application/vnd.ms-powerpoint';
      $file_extensions['mpp']     = 'application/vnd.ms-project';
      $file_extensions['wcm']     = 'application/vnd.ms-works';
      $file_extensions['wdb']     = 'application/vnd.ms-works';
      $file_extensions['wks']     = 'application/vnd.ms-works';
      $file_extensions['wps']     = 'application/vnd.ms-works';
      $file_extensions['wri']     = 'application/x-mswrite';
      $file_extensions['mdb']     = 'application/x-msaccess';
      $file_extensions['crd']     = 'application/x-mscardfile';
      $file_extensions['clp']     = 'application/x-msclip';
      $file_extensions['dll']     = 'application/x-msdownload';
      $file_extensions['m13']     = 'application/x-msmediaview';
      $file_extensions['m14']     = 'application/x-msmediaview';
      $file_extensions['mvb']     = 'application/x-msmediaview';
      $file_extensions['wmf']     = 'application/x-msmetafile';
      $file_extensions['mny']     = 'application/x-msmoney';
      $file_extensions['pub']     = 'application/x-mspublisher';
      $file_extensions['scd']     = 'application/x-msschedule';
      $file_extensions['trm']     = 'application/x-msterminal';
 
      $file_extensions['mp3']     = 'audio/mpeg';
      $file_extensions['ogg']     = 'audio/ogg';
      $file_extensions['au']      = 'audio/basic';
      $file_extensions['snd']     = 'audio/basic';
      $file_extensions['mid']     = 'audio/mid';
      $file_extensions['rmi']     = 'audio/mid';
      $file_extensions['wav']     = 'audio/x-wav';
      $file_extensions['wma']     = 'audio/x-ms-wma';
      $file_extensions['aif']     = 'audio/x-aiff';
      $file_extensions['aifc']    = 'audio/x-aiff';
      $file_extensions['aiff']    = 'audio/x-aiff';
      $file_extensions['m3u']     = 'audio/x-mpegurl';
      $file_extensions['ra']      = 'audio/x-pn-realaudio';
      $file_extensions['ram']     = 'audio/x-pn-realaudio';
 
      $file_extensions['avi']     = 'video/x-msvideo';
      $file_extensions['mov']     = 'video/quicktime';
      $file_extensions['mp4']     = 'video/mp4';
      $file_extensions['mpg']     = 'video/mpeg';
      $file_extensions['mpeg']    = 'video/mpeg';
      $file_extensions['wmv']     = 'video/x-ms-wmv';
      $file_extensions['mp2']     = 'video/mpeg';
      $file_extensions['mpa']     = 'video/mpeg';
      $file_extensions['mpe']     = 'video/mpeg';
      $file_extensions['mpv2']    = 'video/mpeg';
      $file_extensions['qt']      = 'video/quicktime';
      $file_extensions['lsf']     = 'video/x-la-asf';
      $file_extensions['lsx']     = 'video/x-la-asf';
      $file_extensions['asf']     = 'video/x-ms-asf';
      $file_extensions['asr']     = 'video/x-ms-asf';
      $file_extensions['asx']     = 'video/x-ms-asf';
      $file_extensions['movie']   = 'video/x-sgi-movie';
    }
 
    return $file_extensions;
  }
 
?>