From 805a7324cc6f7d6cfdc9fd6296f878ffc90bfa39 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 9 Oct 2019 15:20:19 +0900 Subject: [PATCH] =?UTF-8?q?Storage::getContentType()=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20MIME=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/image.php | 4 ++-- common/framework/mime.php | 32 ++++++++++++++++++++++++++++++++ common/framework/storage.php | 32 -------------------------------- modules/file/file.controller.php | 4 ++-- 4 files changed, 36 insertions(+), 36 deletions(-) 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'];