diff --git a/common/framework/image.php b/common/framework/image.php index 882663eed..ff638f3a9 100644 --- a/common/framework/image.php +++ b/common/framework/image.php @@ -15,7 +15,7 @@ class Image */ public static function isImage($filename) { - return array_shift(explode('/', Storage::getContentType($filename))) === 'image'; + return array_shift(explode('/', MIME::getContentType($filename))) === 'image'; } /** @@ -26,7 +26,7 @@ class Image */ public static function isAnimatedGIF($filename) { - if (Storage::getContentType($filename) !== 'image/gif') + if (MIME::getContentType($filename) !== 'image/gif') { return false; } diff --git a/common/framework/mime.php b/common/framework/mime.php index 7fa4cab6d..6bc622e94 100644 --- a/common/framework/mime.php +++ b/common/framework/mime.php @@ -7,6 +7,38 @@ namespace Rhymix\Framework; */ class MIME { + /** + * Get the MIME type of a file, detected by its content. + * + * This method returns the MIME type of a file, or false on error. + * + * @param string $filename + * @return array|false + */ + public static function getContentType($filename) + { + $filename = rtrim($filename, '/\\'); + if (Storage::exists($filename) && @is_file($filename) && @is_readable($filename)) + { + if (function_exists('mime_content_type')) + { + return @mime_content_type($filename) ?: false; + } + elseif (($image = @getimagesize($filename)) && $image['mime']) + { + return $image['mime']; + } + else + { + return self::getTypeByFilename($filename); + } + } + else + { + return false; + } + } + /** * Get the MIME type for the given extension. * diff --git a/common/framework/storage.php b/common/framework/storage.php index 30ee1bc1d..2d4a97fbd 100644 --- a/common/framework/storage.php +++ b/common/framework/storage.php @@ -143,38 +143,6 @@ class Storage return @self::exists($path) && @is_writable($path); } - /** - * Get the MIME content type of a file. - * - * This method returns the MIME content type of a file, or false on error. - * - * @param string $filename - * @return array|false - */ - public static function getContentType($filename) - { - $filename = rtrim($filename, '/\\'); - if (self::exists($filename) && @is_file($filename) && @is_readable($filename)) - { - if (function_exists('mime_content_type')) - { - return @mime_content_type($filename) ?: false; - } - elseif (($image = @getimagesize($filename)) && $image['mime']) - { - return $image['mime']; - } - else - { - return MIME::getTypeByFilename($filename); - } - } - else - { - return false; - } - } - /** * Get the size of a file. * diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index 97fbc79b8..f7677cb4c 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -875,7 +875,7 @@ class fileController extends file // Set base information $file_info['name'] = Rhymix\Framework\Filters\FilenameFilter::clean($file_info['name']); - $file_info['type'] = $file_info['original_type'] = Rhymix\Framework\Storage::getContentType($file_info['tmp_name']); + $file_info['type'] = $file_info['original_type'] = Rhymix\Framework\MIME::getContentType($file_info['tmp_name']); $file_info['extension'] = $file_info['original_extension'] = strtolower(array_pop(explode('.', $file_info['name']))); $file_info['width'] = null; $file_info['height'] = null; @@ -1250,7 +1250,7 @@ class fileController extends file { $file_info['tmp_name'] = $output_name; $file_info['size'] = filesize($output_name); - $file_info['type'] = Rhymix\Framework\Storage::getContentType($output_name); + $file_info['type'] = Rhymix\Framework\MIME::getContentType($output_name); $file_info['extension'] = $adjusted['type']; $file_info['width'] = $adjusted['width']; $file_info['height'] = $adjusted['height'];