@@ -1746,15 +1746,17 @@ private static function __getCloudFrontResponse(&$rest)
17461746 /**
17471747 * Get MIME type for file
17481748 *
1749+ * To override the putObject() Content-Type, add it to $requestHeaders
1750+ *
1751+ * To use fileinfo, ensure the MAGIC environment variable is set
1752+ *
17491753 * @internal Used to get mime types
17501754 * @param string &$file File path
17511755 * @return string
17521756 */
1753- public static function __getMimeType (&$ file )
1757+ private static function __getMimeType (&$ file )
17541758 {
1755- $ type = false ;
1756- // Fileinfo documentation says fileinfo_open() will use the
1757- // MAGIC env var for the magic file
1759+ // Use fileinfo if available
17581760 if (extension_loaded ('fileinfo ' ) && isset ($ _ENV ['MAGIC ' ]) &&
17591761 ($ finfo = finfo_open (FILEINFO_MIME , $ _ENV ['MAGIC ' ])) !== false )
17601762 {
@@ -1767,30 +1769,31 @@ public static function __getMimeType(&$file)
17671769 $ type = trim (array_shift ($ type ));
17681770 }
17691771 finfo_close ($ finfo );
1772+ if ($ type !== false && strlen ($ type ) > 0 ) return $ type ;
1773+ }
17701774
1771- // If anyone is still using mime_content_type()
1772- } elseif (function_exists ('mime_content_type ' ))
1773- $ type = trim (mime_content_type ($ file ));
1774-
1775- if ($ type !== false && strlen ($ type ) > 0 ) return $ type ;
1776-
1777- // Otherwise do it the old fashioned way
17781775 static $ exts = array (
1779- 'jpg ' => 'image/jpeg ' , 'gif ' => 'image/gif ' , 'png ' => 'image/png ' ,
1780- 'tif ' => 'image/tiff ' , 'tiff ' => 'image/tiff ' , 'ico ' => 'image/x-icon ' ,
1781- 'swf ' => 'application/x-shockwave-flash ' , 'pdf ' => 'application/pdf ' ,
1776+ 'jpg ' => 'image/jpeg ' , 'jpeg ' => 'image/jpeg ' , 'gif ' => 'image/gif ' ,
1777+ 'png ' => 'image/png ' , 'ico ' => 'image/x-icon ' , 'pdf ' => 'application/pdf ' ,
1778+ 'tif ' => 'image/tiff ' , 'tiff ' => 'image/tiff ' , 'svg ' => 'image/svg+xml ' ,
1779+ 'svgz ' => 'image/svg+xml ' , 'swf ' => 'application/x-shockwave-flash ' ,
17821780 'zip ' => 'application/zip ' , 'gz ' => 'application/x-gzip ' ,
17831781 'tar ' => 'application/x-tar ' , 'bz ' => 'application/x-bzip ' ,
1784- 'bz2 ' => 'application/x-bzip2 ' , 'txt ' => 'text/plain ' ,
1782+ 'bz2 ' => 'application/x-bzip2 ' , 'rar ' => 'application/x-rar-compressed ' ,
1783+ 'exe ' => 'application/x-msdownload ' , 'msi ' => 'application/x-msdownload ' ,
1784+ 'cab ' => 'application/vnd.ms-cab-compressed ' , 'txt ' => 'text/plain ' ,
17851785 'asc ' => 'text/plain ' , 'htm ' => 'text/html ' , 'html ' => 'text/html ' ,
17861786 'css ' => 'text/css ' , 'js ' => 'text/javascript ' ,
17871787 'xml ' => 'text/xml ' , 'xsl ' => 'application/xsl+xml ' ,
17881788 'ogg ' => 'application/ogg ' , 'mp3 ' => 'audio/mpeg ' , 'wav ' => 'audio/x-wav ' ,
17891789 'avi ' => 'video/x-msvideo ' , 'mpg ' => 'video/mpeg ' , 'mpeg ' => 'video/mpeg ' ,
17901790 'mov ' => 'video/quicktime ' , 'flv ' => 'video/x-flv ' , 'php ' => 'text/x-php '
17911791 );
1792- $ ext = strtolower (pathInfo ($ file , PATHINFO_EXTENSION ));
1793- return isset ($ exts [$ ext ]) ? $ exts [$ ext ] : 'application/octet-stream ' ;
1792+ $ ext = strtolower (pathinfo ($ file , PATHINFO_EXTENSION ));
1793+ // mime_content_type() is deprecated, fileinfo should be configured
1794+ $ type = isset ($ exts [$ ext ]) ? $ exts [$ ext ] : trim (mime_content_type ($ file ));
1795+
1796+ return ($ type !== false && strlen ($ type ) > 0 ) ? $ type : 'application/octet-stream ' ;
17941797 }
17951798
17961799
0 commit comments