3232* Amazon S3 PHP class
3333*
3434* @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class
35- * @version 0.5.0
35+ * @version 0.5.1-dev
3636*/
3737class S3
3838{
@@ -623,7 +623,7 @@ public static function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE
623623 if (isset ($ requestHeaders ['Content-Type ' ]))
624624 $ input ['type ' ] =& $ requestHeaders ['Content-Type ' ];
625625 elseif (isset ($ input ['file ' ]))
626- $ input ['type ' ] = self ::__getMimeType ($ input ['file ' ]);
626+ $ input ['type ' ] = self ::__getMIMEType ($ input ['file ' ]);
627627 else
628628 $ input ['type ' ] = 'application/octet-stream ' ;
629629 }
@@ -1767,24 +1767,8 @@ private static function __getCloudFrontResponse(&$rest)
17671767 * @param string &$file File path
17681768 * @return string
17691769 */
1770- private static function __getMimeType (&$ file )
1770+ private static function __getMIMEType (&$ file )
17711771 {
1772- // Use fileinfo if available
1773- if (extension_loaded ('fileinfo ' ) && isset ($ _ENV ['MAGIC ' ]) &&
1774- ($ finfo = finfo_open (FILEINFO_MIME , $ _ENV ['MAGIC ' ])) !== false )
1775- {
1776- if (($ type = finfo_file ($ finfo , $ file )) !== false )
1777- {
1778- // Remove the charset and grab the last content-type
1779- $ type = explode (' ' , str_replace ('; charset= ' , ';charset= ' , $ type ));
1780- $ type = array_pop ($ type );
1781- $ type = explode ('; ' , $ type );
1782- $ type = trim (array_shift ($ type ));
1783- }
1784- finfo_close ($ finfo );
1785- if ($ type !== false && strlen ($ type ) > 0 ) return $ type ;
1786- }
1787-
17881772 static $ exts = array (
17891773 'jpg ' => 'image/jpeg ' , 'jpeg ' => 'image/jpeg ' , 'gif ' => 'image/gif ' ,
17901774 'png ' => 'image/png ' , 'ico ' => 'image/x-icon ' , 'pdf ' => 'application/pdf ' ,
@@ -1802,9 +1786,25 @@ private static function __getMimeType(&$file)
18021786 'avi ' => 'video/x-msvideo ' , 'mpg ' => 'video/mpeg ' , 'mpeg ' => 'video/mpeg ' ,
18031787 'mov ' => 'video/quicktime ' , 'flv ' => 'video/x-flv ' , 'php ' => 'text/x-php '
18041788 );
1789+
18051790 $ ext = strtolower (pathinfo ($ file , PATHINFO_EXTENSION ));
1806- // mime_content_type() is deprecated, fileinfo should be configured
1807- $ type = isset ($ exts [$ ext ]) ? $ exts [$ ext ] : trim (mime_content_type ($ file ));
1791+ if (isset ($ exts [$ ext ])) return $ exts [$ ext ];
1792+
1793+ // Use fileinfo if available
1794+ if (extension_loaded ('fileinfo ' ) && isset ($ _ENV ['MAGIC ' ]) &&
1795+ ($ finfo = finfo_open (FILEINFO_MIME , $ _ENV ['MAGIC ' ])) !== false )
1796+ {
1797+ if (($ type = finfo_file ($ finfo , $ file )) !== false )
1798+ {
1799+ // Remove the charset and grab the last content-type
1800+ $ type = explode (' ' , str_replace ('; charset= ' , ';charset= ' , $ type ));
1801+ $ type = array_pop ($ type );
1802+ $ type = explode ('; ' , $ type );
1803+ $ type = trim (array_shift ($ type ));
1804+ }
1805+ finfo_close ($ finfo );
1806+ if ($ type !== false && strlen ($ type ) > 0 ) return $ type ;
1807+ }
18081808
18091809 return ($ type !== false && strlen ($ type ) > 0 ) ? $ type : 'application/octet-stream ' ;
18101810 }
0 commit comments