d72041256522ea1e15e7df2ca822e46a0fb927d2
[lhc/web/wiklou.git] / includes / MimeMagic.php
1 <?php
2 /** Module defining helper functions for detecting and dealing with mime types.
3 *
4 * @package MediaWiki
5 */
6
7 /** Defines a set of well known mime types
8 * This is used as a fallback to mime.types files.
9 * An extensive list of well known mime types is provided by
10 * the file mime.types in the includes directory.
11 */
12 define('MM_WELL_KNOWN_MIME_TYPES',<<<END_STRING
13 application/ogg ogg ogm
14 application/pdf pdf
15 application/x-javascript js
16 application/x-shockwave-flash swf
17 audio/midi mid midi kar
18 audio/mpeg mpga mpa mp2 mp3
19 audio/x-aiff aif aiff aifc
20 audio/x-wav wav
21 audio/ogg ogg
22 image/x-bmp bmp
23 image/gif gif
24 image/jpeg jpeg jpg jpe
25 image/png png
26 image/svg+xml svg
27 image/tiff tiff tif
28 text/plain txt
29 text/html html htm
30 video/ogg ogm ogg
31 video/mpeg mpg mpeg
32 END_STRING
33 );
34
35 /** Defines a set of well known mime info entries
36 * This is used as a fallback to mime.info files.
37 * An extensive list of well known mime types is provided by
38 * the file mime.info in the includes directory.
39 */
40 define('MM_WELL_KNOWN_MIME_INFO', <<<END_STRING
41 application/pdf [OFFICE]
42 text/javascript application/x-javascript [EXECUTABLE]
43 application/x-shockwave-flash [MULTIMEDIA]
44 audio/midi [AUDIO]
45 audio/x-aiff [AUDIO]
46 audio/x-wav [AUDIO]
47 audio/mp3 audio/mpeg [AUDIO]
48 application/ogg audio/ogg video/ogg [MULTIMEDIA]
49 image/x-bmp image/bmp [BITMAP]
50 image/gif [BITMAP]
51 image/jpeg [BITMAP]
52 image/png [BITMAP]
53 image/svg image/svg+xml [DRAWING]
54 image/tiff [BITMAP]
55 text/plain [TEXT]
56 text/html [TEXT]
57 video/ogg [VIDEO]
58 video/mpeg [VIDEO]
59 unknown/unknown application/octet-stream application/x-empty [UNKNOWN]
60 END_STRING
61 );
62
63 #note: because this file is possibly included by a function,
64 #we need to access the global scope explicitely!
65 global $wgLoadFileinfoExtension;
66
67 if ($wgLoadFileinfoExtension) {
68 if(!extension_loaded('fileinfo')) dl('fileinfo.' . PHP_SHLIB_SUFFIX);
69 }
70
71 /** Implements functions related to mime types such as detection and mapping to
72 * file extension,
73 *
74 * Instances of this class are stateles, there only needs to be one global instance
75 * of MimeMagic. Please use wfGetMimeMagic to get that instance.
76 * @package MediaWiki
77 */
78 class MimeMagic {
79
80 /**
81 * Mapping of media types to arrays of mime types.
82 * This is used by findMediaType and getMediaType, respectively
83 */
84 var $mMediaTypes= NULL;
85
86 /** Map of mime type aliases
87 */
88 var $mMimeTypeAliases= NULL;
89
90 /** map of mime types to file extensions (as a space seprarated list)
91 */
92 var $mMimeToExt= NULL;
93
94 /** map of file extensions types to mime types (as a space seprarated list)
95 */
96 var $mExtToMime= NULL;
97
98 /** Initializes the MimeMagic object. This is called by wfGetMimeMagic when instantiation
99 * the global MimeMagic singleton object.
100 *
101 * This constructor parses the mime.types and mime.info files and build internal mappings.
102 */
103 function MimeMagic() {
104 /*
105 * --- load mime.types ---
106 */
107
108 global $wgMimeTypeFile;
109
110 $types= MM_WELL_KNOWN_MIME_TYPES;
111
112 if ($wgMimeTypeFile) {
113 if (is_file($wgMimeTypeFile) and is_readable($wgMimeTypeFile)) {
114 wfDebug("MimeMagic::MimeMagic: loading mime types from $wgMimeTypeFile\n");
115
116 $types.= "\n";
117 $types.= file_get_contents($wgMimeTypeFile);
118 }
119 else wfDebug("MimeMagic::MimeMagic: can't load mime types from $wgMimeTypeFile\n");
120 }
121 else wfDebug("MimeMagic::MimeMagic: no mime types file defined, using build-ins only.\n");
122
123 $types= str_replace(array("\r\n","\n\r","\n\n","\r\r","\r"),"\n",$types);
124 $types= str_replace("\t"," ",$types);
125
126 $this->mMimeToExt= array();
127 $this->mToMime= array();
128
129 $lines= explode("\n",$types);
130 foreach ($lines as $s) {
131 $s= trim($s);
132 if (empty($s)) continue;
133 if (strpos($s,'#')===0) continue;
134
135 $s= strtolower($s);
136 $i= strpos($s,' ');
137
138 if ($i===false) continue;
139
140 #print "processing MIME line $s<br>";
141
142 $mime= substr($s,0,$i);
143 $ext= trim(substr($s,$i+1));
144
145 if (empty($ext)) continue;
146
147 if (@$this->mMimeToExt[$mime]) $this->mMimeToExt[$mime] .= ' '.$ext;
148 else $this->mMimeToExt[$mime]= $ext;
149
150 $extensions= explode(' ',$ext);
151
152 foreach ($extensions as $e) {
153 $e= trim($e);
154 if (empty($e)) continue;
155
156 if (@$this->mExtToMime[$e]) $this->mExtToMime[$e] .= ' '.$mime;
157 else $this->mExtToMime[$e]= $mime;
158 }
159 }
160
161 /*
162 * --- load mime.info ---
163 */
164
165 global $wgMimeInfoFile;
166
167 $info= MM_WELL_KNOWN_MIME_INFO;
168
169 if ($wgMimeInfoFile) {
170 if (is_file($wgMimeInfoFile) and is_readable($wgMimeInfoFile)) {
171 wfDebug("MimeMagic::MimeMagic: loading mime info from $wgMimeInfoFile\n");
172
173 $info.= "\n";
174 $info.= file_get_contents($wgMimeInfoFile);
175 }
176 else wfDebug("MimeMagic::MimeMagic: can't load mime info from $wgMimeInfoFile\n");
177 }
178 else wfDebug("MimeMagic::MimeMagic: no mime info file defined, using build-ins only.\n");
179
180 $info= str_replace(array("\r\n","\n\r","\n\n","\r\r","\r"),"\n",$info);
181 $info= str_replace("\t"," ",$info);
182
183 $this->mMimeTypeAliases= array();
184 $this->mMediaTypes= array();
185
186 $lines= explode("\n",$info);
187 foreach ($lines as $s) {
188 $s= trim($s);
189 if (empty($s)) continue;
190 if (strpos($s,'#')===0) continue;
191
192 $s= strtolower($s);
193 $i= strpos($s,' ');
194
195 if ($i===false) continue;
196
197 #print "processing MIME INFO line $s<br>";
198
199 $match= array();
200 if (preg_match('!\[\s*(\w+)\s*\]!',$s,$match)) {
201 $s= preg_replace('!\[\s*(\w+)\s*\]!','',$s);
202 $mtype= trim(strtoupper($match[1]));
203 }
204 else $mtype= MEDIATYPE_UNKNOWN;
205
206 $m= explode(' ',$s);
207
208 if (!isset($this->mMediaTypes[$mtype])) $this->mMediaTypes[$mtype]= array();
209
210 foreach ($m as $mime) {
211 $mime= trim($mime);
212 if (empty($mime)) continue;
213
214 $this->mMediaTypes[$mtype][]= $mime;
215 }
216
217 if (sizeof($m)>1) {
218 $main= $m[0];
219 for ($i=1; $i<sizeof($m); $i+= 1) {
220 $mime= $m[$i];
221 $this->mMimeTypeAliases[$mime]= $main;
222 }
223 }
224 }
225
226 }
227
228 /** returns a list of file extensions for a given mime type
229 * as a space separated string.
230 */
231 function getExtensionsForType($mime) {
232 $mime= strtolower($mime);
233
234 $r= @$this->mMimeToExt[$mime];
235
236 if (@!$r and isset($this->mMimeTypeAliases[$mime])) {
237 $mime= $this->mMimeTypeAliases[$mime];
238 $r= @$this->mMimeToExt[$mime];
239 }
240
241 return $r;
242 }
243
244 /** returns a list of mime types for a given file extension
245 * as a space separated string.
246 */
247 function getTypesForExtension($ext) {
248 $ext= strtolower($ext);
249
250 $r= @$this->mExtToMime[$ext];
251 return $r;
252 }
253
254 /** returns a single mime type for a given file extension.
255 * This is always the first type from the list returned by getTypesForExtension($ext).
256 */
257 function guessTypesForExtension($ext) {
258 $m= $this->getTypesForExtension( $ext );
259 if( is_null($m) ) return NULL;
260
261 $m= trim( $m );
262 $m= preg_replace('/\s.*$/','',$m);
263
264 return $m;
265 }
266
267
268 /** tests if the extension matches the given mime type.
269 * returns true if a match was found, NULL if the mime type is unknown,
270 * and false if the mime type is known but no matches where found.
271 */
272 function isMatchingExtension($extension,$mime) {
273 $ext= $this->getExtensionsForType($mime);
274
275 if (!$ext) {
276 return NULL; //unknown
277 }
278
279 $ext= explode(' ',$ext);
280
281 $extension= strtolower($extension);
282 if (in_array($extension,$ext)) {
283 return true;
284 }
285
286 return false;
287 }
288
289 /** returns true if the mime type is known to represent
290 * an image format supported by the PHP GD library.
291 */
292 function isPHPImageType( $mime ) {
293 #as defined by imagegetsize and image_type_to_mime
294 static $types = array(
295 'image/gif', 'image/jpeg', 'image/png',
296 'image/x-bmp', 'image/xbm', 'image/tiff',
297 'image/jp2', 'image/jpeg2000', 'image/iff',
298 'image/xbm', 'image/x-xbitmap',
299 'image/vnd.wap.wbmp', 'image/vnd.xiff',
300 'image/x-photoshop',
301 'application/x-shockwave-flash',
302 );
303
304 return in_array( $mime, $types );
305 }
306
307 /**
308 * Returns true if the extension represents a type which can
309 * be reliably detected from its content. Use this to determine
310 * whether strict content checks should be applied to reject
311 * invalid uploads; if we can't identify the type we won't
312 * be able to say if it's invalid.
313 *
314 * @todo Be more accurate when using fancy mime detector plugins;
315 * right now this is the bare minimum getimagesize() list.
316 * @return bool
317 */
318 function isRecognizableExtension( $extension ) {
319 static $types = array(
320 'gif', 'jpeg', 'jpg', 'png', 'swf', 'psd',
321 'bmp', 'tiff', 'tif', 'jpc', 'jp2',
322 'jpx', 'jb2', 'swc', 'iff', 'wbmp',
323 'xbm'
324 );
325 return in_array( strtolower( $extension ), $types );
326 }
327
328
329 /** mime type detection. This uses detectMimeType to detect the mim type of the file,
330 * but applies additional checks to determine some well known file formats that may be missed
331 * or misinterpreter by the default mime detection (namely xml based formats like XHTML or SVG).
332 *
333 * @param string $file The file to check
334 * @param bool $useExt switch for allowing to use the file extension to guess the mime type. true by default.
335 *
336 * @return string the mime type of $file
337 */
338 function guessMimeType( $file, $useExt=true ) {
339 $fname = 'MimeMagic::guessMimeType';
340 $mime= $this->detectMimeType($file,$useExt);
341
342 if (strpos($mime,"text/")===0 ||
343 $mime==="application/xml") {
344
345 // Read a chunk of the file
346 $f = fopen( $file, "rt" );
347 if( !$f ) return "unknown/unknown";
348 $head = fread( $f, 1024 );
349 fclose( $f );
350
351 $xml_type= NULL;
352 $script_type= NULL;
353
354 /*
355 * look for XML formats (XHTML and SVG)
356 */
357 if ($mime==="text/sgml" ||
358 $mime==="text/plain" ||
359 $mime==="text/html" ||
360 $mime==="text/xml" ||
361 $mime==="application/xml") {
362
363 if (substr($head,0,5)=="<?xml") $xml_type= "ASCII";
364 elseif (substr($head,0,8)=="\xef\xbb\xbf<?xml") $xml_type= "UTF-8";
365 elseif (substr($head,0,10)=="\xfe\xff\x00<\x00?\x00x\x00m\x00l") $xml_type= "UTF-16BE";
366 elseif (substr($head,0,10)=="\xff\xfe<\x00?\x00x\x00m\x00l\x00") $xml_type= "UTF-16LE";
367
368 if ($xml_type) {
369 if ($xml_type!=="UTF-8" && $xml_type!=="ASCII") $head= iconv($xml_type,"ASCII//IGNORE",$head);
370
371 $match= array();
372 $doctype= "";
373 $tag= "";
374
375 if (preg_match('%<!DOCTYPE\s+[\w-]+\s+PUBLIC\s+["'."'".'"](.*?)["'."'".'"].*>%sim',$head,$match)) $doctype= $match[1];
376 if (preg_match('%<(\w+).*>%sim',$head,$match)) $tag= $match[1];
377
378 #print "<br>ANALYSING $file ($mime): doctype= $doctype; tag= $tag<br>";
379
380 if (strpos($doctype,"-//W3C//DTD SVG")===0) $mime= "image/svg";
381 elseif ($tag==="svg") $mime= "image/svg";
382 elseif (strpos($doctype,"-//W3C//DTD XHTML")===0) $mime= "text/html";
383 elseif ($tag==="html") $mime= "text/html";
384
385 $test_more= false;
386 }
387 }
388
389 /*
390 * look for shell scripts
391 */
392 if (!$xml_type) {
393 $script_type= NULL;
394
395 #detect by shebang
396 if (substr($head,0,2)=="#!") $script_type= "ASCII";
397 elseif (substr($head,0,5)=="\xef\xbb\xbf#!") $script_type= "UTF-8";
398 elseif (substr($head,0,7)=="\xfe\xff\x00#\x00!") $script_type= "UTF-16BE";
399 elseif (substr($head,0,7)=="\xff\xfe#\x00!") $script_type= "UTF-16LE";
400
401 if ($script_type) {
402 if ($script_type!=="UTF-8" && $script_type!=="ASCII") $head= iconv($script_type,"ASCII//IGNORE",$head);
403
404 $match= array();
405 $prog= "";
406
407 if (preg_match('%/?([^\s]+/)(w+)%sim',$head,$match)) $script= $match[2];
408
409 $mime= "application/x-$prog";
410 }
411 }
412
413 /*
414 * look for PHP
415 */
416 if( !$xml_type && !$script_type ) {
417
418 if( ( strpos( $head, '<?php' ) !== false ) ||
419 ( strpos( $head, '<? ' ) !== false ) ||
420 ( strpos( $head, "<?\n" ) !== false ) ||
421 ( strpos( $head, "<?\t" ) !== false ) ||
422 ( strpos( $head, "<?=" ) !== false ) ||
423
424 ( strpos( $head, "<\x00?\x00p\x00h\x00p" ) !== false ) ||
425 ( strpos( $head, "<\x00?\x00 " ) !== false ) ||
426 ( strpos( $head, "<\x00?\x00\n" ) !== false ) ||
427 ( strpos( $head, "<\x00?\x00\t" ) !== false ) ||
428 ( strpos( $head, "<\x00?\x00=" ) !== false ) ) {
429
430 $mime= "application/x-php";
431 }
432 }
433
434 }
435
436 if (isset($this->mMimeTypeAliases[$mime])) $mime= $this->mMimeTypeAliases[$mime];
437
438 wfDebug("$fname: final mime type of $file: $mime\n");
439 return $mime;
440 }
441
442 /** Internal mime type detection, please use guessMimeType() for application code instead.
443 * Detection is done using an external program, if $wgMimeDetectorCommand is set.
444 * Otherwise, the fileinfo extension and mime_content_type are tried (in this order), if they are available.
445 * If the dections fails and $useExt is true, the mime type is guessed from the file extension, using guessTypesForExtension.
446 * If the mime type is still unknown, getimagesize is used to detect the mime type if the file is an image.
447 * If no mime type can be determined, this function returns "unknown/unknown".
448 *
449 * @param string $file The file to check
450 * @param bool $useExt switch for allowing to use the file extension to guess the mime type. true by default.
451 *
452 * @return string the mime type of $file
453 * @private
454 */
455 function detectMimeType( $file, $useExt=true ) {
456 $fname = 'MimeMagic::detectMimeType';
457
458 global $wgMimeDetectorCommand;
459
460 $m= NULL;
461 if ($wgMimeDetectorCommand) {
462 $fn= wfEscapeShellArg($file);
463 $m= `$wgMimeDetectorCommand $fn`;
464 }
465 else if (function_exists("finfo_open") && function_exists("finfo_file")) {
466
467 # This required the fileinfo extension by PECL,
468 # see http://pecl.php.net/package/fileinfo
469 # This must be compiled into PHP
470 #
471 # finfo is the official replacement for the deprecated
472 # mime_content_type function, see below.
473 #
474 # If you may need to load the fileinfo extension at runtime, set
475 # $wgLoadFileinfoExtension in LocalSettings.php
476
477 $mime_magic_resource = finfo_open(FILEINFO_MIME); /* return mime type ala mimetype extension */
478
479 if ($mime_magic_resource) {
480 $m= finfo_file($mime_magic_resource, $file);
481
482 finfo_close($mime_magic_resource);
483 }
484 else wfDebug("$fname: finfo_open failed on ".FILEINFO_MIME."!\n");
485 }
486 else if (function_exists("mime_content_type")) {
487
488 # NOTE: this function is available since PHP 4.3.0, but only if
489 # PHP was compiled with --with-mime-magic or, before 4.3.2, with --enable-mime-magic.
490 #
491 # On Winodws, you must set mime_magic.magicfile in php.ini to point to the mime.magic file bundeled with PHP;
492 # sometimes, this may even be needed under linus/unix.
493 #
494 # Also note that this has been DEPRECATED in favor of the fileinfo extension by PECL, see above.
495 # see http://www.php.net/manual/en/ref.mime-magic.php for details.
496
497 $m= mime_content_type($file);
498 }
499 else wfDebug("$fname: no magic mime detector found!\n");
500
501 if ($m) {
502 #normalize
503 $m= preg_replace('![;, ].*$!','',$m); #strip charset, etc
504 $m= trim($m);
505 $m= strtolower($m);
506
507 if (strpos($m,'unknown')!==false) $m= NULL;
508 else {
509 wfDebug("$fname: magic mime type of $file: $m\n");
510 return $m;
511 }
512 }
513
514 #if still not known, use getimagesize to find out the type of image
515 #TODO: skip things that do not have a well-known image extension? Would that be safe?
516 wfSuppressWarnings();
517 $gis = getimagesize( $file );
518 wfRestoreWarnings();
519
520 $notAnImage= false;
521
522 if ($gis && is_array($gis) && $gis[2]) {
523 switch ($gis[2]) {
524 case IMAGETYPE_GIF: $m= "image/gif"; break;
525 case IMAGETYPE_JPEG: $m= "image/jpeg"; break;
526 case IMAGETYPE_PNG: $m= "image/png"; break;
527 case IMAGETYPE_SWF: $m= "application/x-shockwave-flash"; break;
528 case IMAGETYPE_PSD: $m= "application/photoshop"; break;
529 case IMAGETYPE_BMP: $m= "image/bmp"; break;
530 case IMAGETYPE_TIFF_II: $m= "image/tiff"; break;
531 case IMAGETYPE_TIFF_MM: $m= "image/tiff"; break;
532 case IMAGETYPE_JPC: $m= "image"; break;
533 case IMAGETYPE_JP2: $m= "image/jpeg2000"; break;
534 case IMAGETYPE_JPX: $m= "image/jpeg2000"; break;
535 case IMAGETYPE_JB2: $m= "image"; break;
536 case IMAGETYPE_SWC: $m= "application/x-shockwave-flash"; break;
537 case IMAGETYPE_IFF: $m= "image/vnd.xiff"; break;
538 case IMAGETYPE_WBMP: $m= "image/vnd.wap.wbmp"; break;
539 case IMAGETYPE_XBM: $m= "image/x-xbitmap"; break;
540 }
541
542 if ($m) {
543 wfDebug("$fname: image mime type of $file: $m\n");
544 return $m;
545 }
546 else $notAnImage= true;
547 }
548
549 #if desired, look at extension as a fallback.
550 if ($useExt) {
551 $i = strrpos( $file, '.' );
552 $e= strtolower( $i ? substr( $file, $i + 1 ) : '' );
553
554 $m= $this->guessTypesForExtension($e);
555
556 #TODO: if $notAnImage is set, do not trust the file extension if
557 # the results is one of the image types that should have been recognized
558 # by getimagesize
559
560 if ($m) {
561 wfDebug("$fname: extension mime type of $file: $m\n");
562 return $m;
563 }
564 }
565
566 #unknown type
567 wfDebug("$fname: failed to guess mime type for $file!\n");
568 return "unknown/unknown";
569 }
570
571 /**
572 * Determine the media type code for a file, using its mime type, name and possibly
573 * its contents.
574 *
575 * This function relies on the findMediaType(), mapping extensions and mime
576 * types to media types.
577 *
578 * @todo analyse file if need be
579 * @todo look at multiple extension, separately and together.
580 *
581 * @param string $path full path to the image file, in case we have to look at the contents
582 * (if null, only the mime type is used to determine the media type code).
583 * @param string $mime mime type. If null it will be guessed using guessMimeType.
584 *
585 * @return (int?string?) a value to be used with the MEDIATYPE_xxx constants.
586 */
587 function getMediaType($path=NULL,$mime=NULL) {
588 if( !$mime && !$path ) return MEDIATYPE_UNKNOWN;
589
590 #if mime type is unknown, guess it
591 if( !$mime ) $mime= $this->guessMimeType($path,false);
592
593 #special code for ogg - detect if it's video (theora),
594 #else label it as sound.
595 if( $mime=="application/ogg" && file_exists($path) ) {
596
597 // Read a chunk of the file
598 $f = fopen( $path, "rt" );
599 if( !$f ) return MEDIATYPE_UNKNOWN;
600 $head = fread( $f, 256 );
601 fclose( $f );
602
603 $head= strtolower( $head );
604
605 #This is an UGLY HACK, file should be parsed correctly
606 if( strpos($head,'theora')!==false ) return MEDIATYPE_VIDEO;
607 elseif( strpos($head,'vorbis')!==false ) return MEDIATYPE_AUDIO;
608 elseif( strpos($head,'flac')!==false ) return MEDIATYPE_AUDIO;
609 elseif( strpos($head,'speex')!==false ) return MEDIATYPE_AUDIO;
610 else return MEDIATYPE_MULTIMEDIA;
611 }
612
613 #check for entry for full mime type
614 if( $mime ) {
615 $type= $this->findMediaType($mime);
616 if( $type!==MEDIATYPE_UNKNOWN ) return $type;
617 }
618
619 #check for entry for file extension
620 $e= NULL;
621 if( $path ) {
622 $i = strrpos( $path, '.' );
623 $e= strtolower( $i ? substr( $path, $i + 1 ) : '' );
624
625 #TODO: look at multi-extension if this fails, parse from full path
626
627 $type= $this->findMediaType('.'.$e);
628 if( $type!==MEDIATYPE_UNKNOWN ) return $type;
629 }
630
631 #check major mime type
632 if( $mime ) {
633 $i= strpos($mime,'/');
634 if( $i !== false ) {
635 $major= substr($mime,0,$i);
636 $type= $this->findMediaType($major);
637 if( $type!==MEDIATYPE_UNKNOWN ) return $type;
638 }
639 }
640
641 if( !$type ) $type= MEDIATYPE_UNKNOWN;
642
643 return $type;
644 }
645
646 /** returns a media code matching the given mime type or file extension.
647 * File extensions are represented by a string starting with a dot (.) to
648 * distinguish them from mime types.
649 *
650 * This funktion relies on the mapping defined by $this->mMediaTypes
651 * @private
652 */
653 function findMediaType($extMime) {
654
655 if (strpos($extMime,'.')===0) { #if it's an extension, look up the mime types
656 $m= $this->getTypesForExtension(substr($extMime,1));
657 if (!$m) return MEDIATYPE_UNKNOWN;
658
659 $m= explode(' ',$m);
660 }
661 else { #normalize mime type
662 if (isset($this->mMimeTypeAliases[$extMime])) {
663 $extMime= $this->mMimeTypeAliases[$extMime];
664 }
665
666 $m= array($extMime);
667 }
668
669 foreach ($m as $mime) {
670 foreach ($this->mMediaTypes as $type => $codes) {
671 if (in_array($mime,$codes,true)) return $type;
672 }
673 }
674
675 return MEDIATYPE_UNKNOWN;
676 }
677 }
678
679 ?>