* s~ +$~~
[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 // Read a chunk of the file
343 $f = fopen( $file, "rt" );
344 if( !$f ) return "unknown/unknown";
345 $head = fread( $f, 1024 );
346 fclose( $f );
347
348 $sub4 = substr( $head, 0, 4 );
349 if ( $sub4 == "\x01\x00\x09\x00" || $sub4 == "\xd7\xcd\xc6\x9a" ) {
350 // WMF kill kill kill
351 // Note that WMF may have a bare header, no magic number.
352 // The former of the above two checks is theoretically prone to false positives
353 $mime = "application/x-msmetafile";
354 }
355
356 if (strpos($mime,"text/")===0 || $mime==="application/xml") {
357
358 $xml_type= NULL;
359 $script_type= NULL;
360
361 /*
362 * look for XML formats (XHTML and SVG)
363 */
364 if ($mime==="text/sgml" ||
365 $mime==="text/plain" ||
366 $mime==="text/html" ||
367 $mime==="text/xml" ||
368 $mime==="application/xml") {
369
370 if (substr($head,0,5)=="<?xml") $xml_type= "ASCII";
371 elseif (substr($head,0,8)=="\xef\xbb\xbf<?xml") $xml_type= "UTF-8";
372 elseif (substr($head,0,10)=="\xfe\xff\x00<\x00?\x00x\x00m\x00l") $xml_type= "UTF-16BE";
373 elseif (substr($head,0,10)=="\xff\xfe<\x00?\x00x\x00m\x00l\x00") $xml_type= "UTF-16LE";
374
375 if ($xml_type) {
376 if ($xml_type!=="UTF-8" && $xml_type!=="ASCII") $head= iconv($xml_type,"ASCII//IGNORE",$head);
377
378 $match= array();
379 $doctype= "";
380 $tag= "";
381
382 if (preg_match('%<!DOCTYPE\s+[\w-]+\s+PUBLIC\s+["'."'".'"](.*?)["'."'".'"].*>%sim',$head,$match)) $doctype= $match[1];
383 if (preg_match('%<(\w+).*>%sim',$head,$match)) $tag= $match[1];
384
385 #print "<br>ANALYSING $file ($mime): doctype= $doctype; tag= $tag<br>";
386
387 if (strpos($doctype,"-//W3C//DTD SVG")===0) $mime= "image/svg";
388 elseif ($tag==="svg") $mime= "image/svg";
389 elseif (strpos($doctype,"-//W3C//DTD XHTML")===0) $mime= "text/html";
390 elseif ($tag==="html") $mime= "text/html";
391
392 $test_more= false;
393 }
394 }
395
396 /*
397 * look for shell scripts
398 */
399 if (!$xml_type) {
400 $script_type= NULL;
401
402 #detect by shebang
403 if (substr($head,0,2)=="#!") $script_type= "ASCII";
404 elseif (substr($head,0,5)=="\xef\xbb\xbf#!") $script_type= "UTF-8";
405 elseif (substr($head,0,7)=="\xfe\xff\x00#\x00!") $script_type= "UTF-16BE";
406 elseif (substr($head,0,7)=="\xff\xfe#\x00!") $script_type= "UTF-16LE";
407
408 if ($script_type) {
409 if ($script_type!=="UTF-8" && $script_type!=="ASCII") $head= iconv($script_type,"ASCII//IGNORE",$head);
410
411 $match= array();
412 $prog= "";
413
414 if (preg_match('%/?([^\s]+/)(w+)%sim',$head,$match)) $script= $match[2];
415
416 $mime= "application/x-$prog";
417 }
418 }
419
420 /*
421 * look for PHP
422 */
423 if( !$xml_type && !$script_type ) {
424
425 if( ( strpos( $head, '<?php' ) !== false ) ||
426 ( strpos( $head, '<? ' ) !== false ) ||
427 ( strpos( $head, "<?\n" ) !== false ) ||
428 ( strpos( $head, "<?\t" ) !== false ) ||
429 ( strpos( $head, "<?=" ) !== false ) ||
430
431 ( strpos( $head, "<\x00?\x00p\x00h\x00p" ) !== false ) ||
432 ( strpos( $head, "<\x00?\x00 " ) !== false ) ||
433 ( strpos( $head, "<\x00?\x00\n" ) !== false ) ||
434 ( strpos( $head, "<\x00?\x00\t" ) !== false ) ||
435 ( strpos( $head, "<\x00?\x00=" ) !== false ) ) {
436
437 $mime= "application/x-php";
438 }
439 }
440
441 }
442
443 if (isset($this->mMimeTypeAliases[$mime])) $mime= $this->mMimeTypeAliases[$mime];
444
445 wfDebug("$fname: final mime type of $file: $mime\n");
446 return $mime;
447 }
448
449 /** Internal mime type detection, please use guessMimeType() for application code instead.
450 * Detection is done using an external program, if $wgMimeDetectorCommand is set.
451 * Otherwise, the fileinfo extension and mime_content_type are tried (in this order), if they are available.
452 * If the dections fails and $useExt is true, the mime type is guessed from the file extension, using guessTypesForExtension.
453 * If the mime type is still unknown, getimagesize is used to detect the mime type if the file is an image.
454 * If no mime type can be determined, this function returns "unknown/unknown".
455 *
456 * @param string $file The file to check
457 * @param bool $useExt switch for allowing to use the file extension to guess the mime type. true by default.
458 *
459 * @return string the mime type of $file
460 * @access private
461 */
462 function detectMimeType( $file, $useExt=true ) {
463 $fname = 'MimeMagic::detectMimeType';
464
465 global $wgMimeDetectorCommand;
466
467 $m= NULL;
468 if ($wgMimeDetectorCommand) {
469 $fn= wfEscapeShellArg($file);
470 $m= `$wgMimeDetectorCommand $fn`;
471 }
472 else if (function_exists("finfo_open") && function_exists("finfo_file")) {
473
474 # This required the fileinfo extension by PECL,
475 # see http://pecl.php.net/package/fileinfo
476 # This must be compiled into PHP
477 #
478 # finfo is the official replacement for the deprecated
479 # mime_content_type function, see below.
480 #
481 # If you may need to load the fileinfo extension at runtime, set
482 # $wgLoadFileinfoExtension in LocalSettings.php
483
484 $mime_magic_resource = finfo_open(FILEINFO_MIME); /* return mime type ala mimetype extension */
485
486 if ($mime_magic_resource) {
487 $m= finfo_file($mime_magic_resource, $file);
488
489 finfo_close($mime_magic_resource);
490 }
491 else wfDebug("$fname: finfo_open failed on ".FILEINFO_MIME."!\n");
492 }
493 else if (function_exists("mime_content_type")) {
494
495 # NOTE: this function is available since PHP 4.3.0, but only if
496 # PHP was compiled with --with-mime-magic or, before 4.3.2, with --enable-mime-magic.
497 #
498 # On Winodws, you must set mime_magic.magicfile in php.ini to point to the mime.magic file bundeled with PHP;
499 # sometimes, this may even be needed under linus/unix.
500 #
501 # Also note that this has been DEPRECATED in favor of the fileinfo extension by PECL, see above.
502 # see http://www.php.net/manual/en/ref.mime-magic.php for details.
503
504 $m= mime_content_type($file);
505 }
506 else wfDebug("$fname: no magic mime detector found!\n");
507
508 if ($m) {
509 #normalize
510 $m= preg_replace('![;, ].*$!','',$m); #strip charset, etc
511 $m= trim($m);
512 $m= strtolower($m);
513
514 if (strpos($m,'unknown')!==false) $m= NULL;
515 else {
516 wfDebug("$fname: magic mime type of $file: $m\n");
517 return $m;
518 }
519 }
520
521 #if still not known, use getimagesize to find out the type of image
522 #TODO: skip things that do not have a well-known image extension? Would that be safe?
523 wfSuppressWarnings();
524 $gis = getimagesize( $file );
525 wfRestoreWarnings();
526
527 $notAnImage= false;
528
529 if ($gis && is_array($gis) && $gis[2]) {
530 switch ($gis[2]) {
531 case IMAGETYPE_GIF: $m= "image/gif"; break;
532 case IMAGETYPE_JPEG: $m= "image/jpeg"; break;
533 case IMAGETYPE_PNG: $m= "image/png"; break;
534 case IMAGETYPE_SWF: $m= "application/x-shockwave-flash"; break;
535 case IMAGETYPE_PSD: $m= "application/photoshop"; break;
536 case IMAGETYPE_BMP: $m= "image/bmp"; break;
537 case IMAGETYPE_TIFF_II: $m= "image/tiff"; break;
538 case IMAGETYPE_TIFF_MM: $m= "image/tiff"; break;
539 case IMAGETYPE_JPC: $m= "image"; break;
540 case IMAGETYPE_JP2: $m= "image/jpeg2000"; break;
541 case IMAGETYPE_JPX: $m= "image/jpeg2000"; break;
542 case IMAGETYPE_JB2: $m= "image"; break;
543 case IMAGETYPE_SWC: $m= "application/x-shockwave-flash"; break;
544 case IMAGETYPE_IFF: $m= "image/vnd.xiff"; break;
545 case IMAGETYPE_WBMP: $m= "image/vnd.wap.wbmp"; break;
546 case IMAGETYPE_XBM: $m= "image/x-xbitmap"; break;
547 }
548
549 if ($m) {
550 wfDebug("$fname: image mime type of $file: $m\n");
551 return $m;
552 }
553 else $notAnImage= true;
554 }
555
556 #if desired, look at extension as a fallback.
557 if ($useExt) {
558 $i = strrpos( $file, '.' );
559 $e= strtolower( $i ? substr( $file, $i + 1 ) : '' );
560
561 $m= $this->guessTypesForExtension($e);
562
563 #TODO: if $notAnImage is set, do not trust the file extension if
564 # the results is one of the image types that should have been recognized
565 # by getimagesize
566
567 if ($m) {
568 wfDebug("$fname: extension mime type of $file: $m\n");
569 return $m;
570 }
571 }
572
573 #unknown type
574 wfDebug("$fname: failed to guess mime type for $file!\n");
575 return "unknown/unknown";
576 }
577
578 /**
579 * Determine the media type code for a file, using its mime type, name and possibly
580 * its contents.
581 *
582 * This function relies on the findMediaType(), mapping extensions and mime
583 * types to media types.
584 *
585 * @todo analyse file if need be
586 * @todo look at multiple extension, separately and together.
587 *
588 * @param string $path full path to the image file, in case we have to look at the contents
589 * (if null, only the mime type is used to determine the media type code).
590 * @param string $mime mime type. If null it will be guessed using guessMimeType.
591 *
592 * @return (int?string?) a value to be used with the MEDIATYPE_xxx constants.
593 */
594 function getMediaType($path=NULL,$mime=NULL) {
595 if( !$mime && !$path ) return MEDIATYPE_UNKNOWN;
596
597 #if mime type is unknown, guess it
598 if( !$mime ) $mime= $this->guessMimeType($path,false);
599
600 #special code for ogg - detect if it's video (theora),
601 #else label it as sound.
602 if( $mime=="application/ogg" && file_exists($path) ) {
603
604 // Read a chunk of the file
605 $f = fopen( $path, "rt" );
606 if( !$f ) return MEDIATYPE_UNKNOWN;
607 $head = fread( $f, 256 );
608 fclose( $f );
609
610 $head= strtolower( $head );
611
612 #This is an UGLY HACK, file should be parsed correctly
613 if( strpos($head,'theora')!==false ) return MEDIATYPE_VIDEO;
614 elseif( strpos($head,'vorbis')!==false ) return MEDIATYPE_AUDIO;
615 elseif( strpos($head,'flac')!==false ) return MEDIATYPE_AUDIO;
616 elseif( strpos($head,'speex')!==false ) return MEDIATYPE_AUDIO;
617 else return MEDIATYPE_MULTIMEDIA;
618 }
619
620 #check for entry for full mime type
621 if( $mime ) {
622 $type= $this->findMediaType($mime);
623 if( $type!==MEDIATYPE_UNKNOWN ) return $type;
624 }
625
626 #check for entry for file extension
627 $e= NULL;
628 if( $path ) {
629 $i = strrpos( $path, '.' );
630 $e= strtolower( $i ? substr( $path, $i + 1 ) : '' );
631
632 #TODO: look at multi-extension if this fails, parse from full path
633
634 $type= $this->findMediaType('.'.$e);
635 if( $type!==MEDIATYPE_UNKNOWN ) return $type;
636 }
637
638 #check major mime type
639 if( $mime ) {
640 $i= strpos($mime,'/');
641 if( $i !== false ) {
642 $major= substr($mime,0,$i);
643 $type= $this->findMediaType($major);
644 if( $type!==MEDIATYPE_UNKNOWN ) return $type;
645 }
646 }
647
648 if( !$type ) $type= MEDIATYPE_UNKNOWN;
649
650 return $type;
651 }
652
653 /** returns a media code matching the given mime type or file extension.
654 * File extensions are represented by a string starting with a dot (.) to
655 * distinguish them from mime types.
656 *
657 * This funktion relies on the mapping defined by $this->mMediaTypes
658 * @access private
659 */
660 function findMediaType($extMime) {
661
662 if (strpos($extMime,'.')===0) { #if it's an extension, look up the mime types
663 $m= $this->getTypesForExtension(substr($extMime,1));
664 if (!$m) return MEDIATYPE_UNKNOWN;
665
666 $m= explode(' ',$m);
667 }
668 else { #normalize mime type
669 if (isset($this->mMimeTypeAliases[$extMime])) {
670 $extMime= $this->mMimeTypeAliases[$extMime];
671 }
672
673 $m= array($extMime);
674 }
675
676 foreach ($m as $mime) {
677 foreach ($this->mMediaTypes as $type => $codes) {
678 if (in_array($mime,$codes,true)) return $type;
679 }
680 }
681
682 return MEDIATYPE_UNKNOWN;
683 }
684 }
685
686 ?>