32
32
* Amazon S3 PHP class
33
33
*
34
34
* @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class
35
- * @version 0.5.0
35
+ * @version 0.5.1-dev
36
36
*/
37
37
class S3
38
38
{
@@ -623,7 +623,7 @@ public static function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE
623
623
if (isset ($ requestHeaders ['Content-Type ' ]))
624
624
$ input ['type ' ] =& $ requestHeaders ['Content-Type ' ];
625
625
elseif (isset ($ input ['file ' ]))
626
- $ input ['type ' ] = self ::__getMimeType ($ input ['file ' ]);
626
+ $ input ['type ' ] = self ::__getMIMEType ($ input ['file ' ]);
627
627
else
628
628
$ input ['type ' ] = 'application/octet-stream ' ;
629
629
}
@@ -1767,24 +1767,8 @@ private static function __getCloudFrontResponse(&$rest)
1767
1767
* @param string &$file File path
1768
1768
* @return string
1769
1769
*/
1770
- private static function __getMimeType (&$ file )
1770
+ private static function __getMIMEType (&$ file )
1771
1771
{
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
-
1788
1772
static $ exts = array (
1789
1773
'jpg ' => 'image/jpeg ' , 'jpeg ' => 'image/jpeg ' , 'gif ' => 'image/gif ' ,
1790
1774
'png ' => 'image/png ' , 'ico ' => 'image/x-icon ' , 'pdf ' => 'application/pdf ' ,
@@ -1802,9 +1786,25 @@ private static function __getMimeType(&$file)
1802
1786
'avi ' => 'video/x-msvideo ' , 'mpg ' => 'video/mpeg ' , 'mpeg ' => 'video/mpeg ' ,
1803
1787
'mov ' => 'video/quicktime ' , 'flv ' => 'video/x-flv ' , 'php ' => 'text/x-php '
1804
1788
);
1789
+
1805
1790
$ 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
+ }
1808
1808
1809
1809
return ($ type !== false && strlen ($ type ) > 0 ) ? $ type : 'application/octet-stream ' ;
1810
1810
}
0 commit comments