? mimedetect-288811-realpath.patch Index: mimedetect.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/mimedetect/mimedetect.install,v retrieving revision 1.6 diff -u -p -r1.6 mimedetect.install --- mimedetect.install 15 Apr 2009 17:46:39 -0000 1.6 +++ mimedetect.install 15 Apr 2009 18:54:34 -0000 @@ -47,8 +47,8 @@ function mimedetect_requirements($phase) } } else { - $requirement['value'] = $t('Browser & Extension'); - $requirement['description'] = $t("MimeDetect is using the browser supplied mime type or file extension lookups. It is strongly recommended that you install and configure the PHP Fileinfo Extension or the UNIX 'file' command to provide more accurate severside mime type detection."); + $requirement['value'] = $t('File Extension'); + $requirement['description'] = $t("MimeDetect is using the browser supplied filename for file extension lookups. It is strongly recommended that you install and configure the PHP Fileinfo Extension or the UNIX 'file' command to provide more accurate severside mime type detection."); $requirement['severity'] = REQUIREMENT_WARNING; } Index: mimedetect.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/mimedetect/mimedetect.module,v retrieving revision 1.8 diff -u -p -r1.8 mimedetect.module --- mimedetect.module 15 Apr 2009 17:49:13 -0000 1.8 +++ mimedetect.module 15 Apr 2009 18:54:34 -0000 @@ -71,74 +71,19 @@ function mimedetect_settings_validate($f function mimedetect_mime($file) { $file = (object)$file; - // Lookup array, just in case we can't figure out the mime type. - static $extension_mimes = array( - // MS ASF derived multimedia filetypes - 'asx' => 'video/x-ms-asf', - 'wma' => 'audio/x-ms-wma', - 'wax' => 'audio/x-ms-wax', - 'wmv' => 'video/x-ms-wmv', - 'wvx' => ' video/x-ms-wvx', - 'wm' => 'video/x-ms-wm', - 'wmx' => 'video/x-ms-wmx', - 'wmz' => 'application/x-ms-wmz', - 'wmd' => 'application/x-ms-wmd', - - // Standard audio types - 'au' => 'audio/basic', - 'snd' => 'audio/basic', - 'mid' => 'audio/mid', - 'rmi' => 'audio/mid', - 'mp3' => 'audio/mpeg', - 'aif' => 'audio/x-aiff', - 'aifc' => 'audio/x-aiff', + // An additional array of mimetypes not included in file_get_mimetype(). + static $additional_mimes = array( + // Audio types + 'rmi' => 'audio/midi', 'aidff' => 'audio/x-aiff', - 'm3u' => 'audio/x-mpegurl', - 'ra' => 'audio/x-pn-realaudio', - 'ram' => 'audio/x-pn-realaudio', - 'wav' => 'audio/x-wav', - - // Standard image types - 'bmp' => 'image/bmp', + // Image types 'cod' => 'image/cis-cod', - 'gif' => 'image/gif', - 'ief' => 'image/ief', - 'jpe' => 'image/jpeg', - 'jpg' => 'image/jpeg', - 'jpeg' => 'image/jpeg', 'jfif' => 'image/pipeg', - 'png' => 'image/png', - 'svg' => 'image/svg+xml', - 'tif' => 'image/tiff', - 'tiff' => 'image/tiff', - 'ras' => 'image/x-cmu-raster', 'cmx' => 'image/x-cmx', - 'ico' => 'image/x-ico', // as in the freedesktop.org MIME info database - IANA prefers 'image/vnd.microsoft.icon' - 'pnm' => 'image/x-portable-anymap', - 'pbm' => 'image/x-portable-bitmap', - 'pgm' => 'image/x-portable-graymap', - 'ppm' => 'image/x-portable-pixmap', - 'rgb' => 'image/x-rgb', - 'xbm' => 'image/x-xbitmap', - 'xpm' => 'image/x-xpixmap', - 'xwd' => 'image/x-xwindowdump', - - // Standard video types - 'mp2' => 'video/mpeg', + // Video types 'mpa' => 'video/mpeg', - 'mpe' => 'video/mpeg', - 'mpeg' => 'video/mpeg', - 'mpg' => 'video/mpeg', 'mpv2' => 'video/mpeg', - 'mov' => 'video/quicktime', - 'qt' => 'video/quicktime', - 'lsf' => 'video/x-la-asf', - 'lsx' => 'video/x-la-asf', - 'asf' => 'video/x-ms-asf', 'asr' => 'video/x-ms-asf', - 'asx' => 'video/x-ms-asf', - 'avi' => 'video/x-msvideo', - 'movie' => 'video/x-sgi-movie', ); $mime = FALSE; @@ -163,25 +108,17 @@ function mimedetect_mime($file) { $mime = trim($mime[0]); } - // Trust the browser... ack! - if (!$mime) { - $mime = $file->filemime; - } - - // ASF derived media formats are hard to detect with magic. They're - // typically all reported as video/x-ms-asf or application/octet-stream - // These aren't really informative about the media type, so we attempt to - // figure it out by extension. - // I expect OGG to present similar difficulties in determining how it should be played... - + // ASF derived media formats are hard to detect with magic. They're typically + // all reported as video/x-ms-asf or application/octet-stream. These aren't + // really informative about the media type, so we attempt to figure it out by + // extension. I expect OGG to present similar difficulties in determining how + // it should be played. if (!$mime || $mime == 'application/octet-stream') { - $parts = explode('.', $file->filename); - $extension = strtolower(array_pop($parts)); - if (isset($extension_mimes[$extension])) { - $mime = $extension_mimes[$extension]; - } - else { - $mime = 'application/octet-stream'; + // Try core's mime mapping first... + $mime = file_get_mimetype($file->filename); + // ...and if that doesn't turn up anything try our additional mappings. + if ($mime == 'application/octet-stream') { + $mime = file_get_mimetype($file->filename, $additional_mimes); } }