From 16e44d44c7c45cde8890e7b989a0285a63ff2751 Mon Sep 17 00:00:00 2001 From: conory Date: Tue, 1 Oct 2019 22:50:38 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9B=80=EC=A7=81=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8A=94=20gif=EB=8F=84=20mp4=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=ED=99=98=EB=90=98=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20FFmpeg=20=EC=82=AC=EC=9A=A9=20=EB=B6=88=EA=B0=80=20?= =?UTF-8?q?=EC=95=88=EB=82=B4=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EC=B6=94=ED=9B=84=EC=97=90=20=ED=99=9C=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20type,=20width,=20heig?= =?UTF-8?q?ht,=20duration=20=EC=BB=AC=EB=9F=BC=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=EC=8B=9C=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80,=20=EC=98=A4=EB=94=94=EC=98=A4,=20=EB=8F=99=EC=98=81?= =?UTF-8?q?=EC=83=81=20=ED=8C=8C=EC=9D=BC=EC=9D=98=20=ED=99=95=EC=9E=A5?= =?UTF-8?q?=EC=9E=90=EA=B0=80=20=EC=9E=98=EB=AA=BB=EB=90=9C=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=98=AC=EB=B0=94=EB=A5=B8=20=ED=99=95=EC=9E=A5?= =?UTF-8?q?=EC=9E=90=EB=A5=BC=20=EB=8D=A7=EB=B6=99=EC=9D=B4=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/image.php | 37 +++- common/framework/storage.php | 77 +++++++ common/framework/video.php | 20 -- common/functions.php | 19 ++ .../js/plugins/jquery.fileupload/js/main.js | 4 +- common/lang/en.php | 1 + common/lang/ko.php | 1 + modules/file/file.admin.view.php | 3 +- modules/file/file.class.php | 45 ++++- modules/file/file.controller.php | 189 +++++++++--------- modules/file/file.model.php | 4 +- modules/file/file.view.php | 27 +-- modules/file/lang/en.php | 3 +- modules/file/lang/ko.php | 3 +- modules/file/queries/insertFile.xml | 4 + modules/file/schemas/files.xml | 4 + modules/file/tpl/file_module_config.html | 55 ++--- modules/file/tpl/upload_config.html | 15 +- 18 files changed, 331 insertions(+), 180 deletions(-) delete mode 100644 common/framework/video.php diff --git a/common/framework/image.php b/common/framework/image.php index 1541207a2..9b8e5e342 100644 --- a/common/framework/image.php +++ b/common/framework/image.php @@ -8,14 +8,43 @@ namespace Rhymix\Framework; class Image { /** - * Check Check if file is an image + * Check if a file is an image * * @param string $filename * @return bool */ public static function isImage($filename) { - return strtolower(array_shift(explode('/', @mime_content_type($filename)))) === 'image'; + return array_shift(explode('/', Storage::getContentType($filename))) === 'image'; + } + + /** + * Check if a file is an animated GIF. + * + * @param string $filename + * @return bool + */ + public static function isAnimatedGIF($filename) + { + if (Storage::getContentType($filename) !== 'image/gif') + { + return false; + } + if (!$fp = @fopen($filename, 'rb')) + { + return false; + } + $frames = 0; + while (!feof($fp) && $frames < 2) + { + $frames += preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', fread($fp, 1024 * 16) ?: ''); + if (!feof($fp)) + { + fseek($fp, -9, SEEK_CUR); + } + } + fclose($fp); + return $frames > 1; } /** @@ -38,9 +67,9 @@ class Image 'width' => $image_info[0], 'height' => $image_info[1], 'type' => image_type_to_extension($image_info[2], false), - 'bits' => $image_info['bits'], - 'channels' => $image_info['channels'], 'mime' => $image_info['mime'], + 'bits' => $image_info['bits'] ?? null, + 'channels' => $image_info['channels'] ?? null, ]; } } diff --git a/common/framework/storage.php b/common/framework/storage.php index 4ac59397d..30ee1bc1d 100644 --- a/common/framework/storage.php +++ b/common/framework/storage.php @@ -143,6 +143,38 @@ 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. * @@ -499,6 +531,51 @@ class Storage return true; } + /** + * Move uploaded $source to $destination. + * + * This method returns true on success and false on failure. + * + * @param string $source + * @param string $destination + * @param string $type + * @return bool + */ + public static function moveUploadedFile($source, $destination, $type = null) + { + if ($type === 'copy') + { + if (!self::copy($source, $destination)) + { + if (!self::copy($source, $destination)) + { + return false; + } + } + } + elseif ($type === 'move') + { + if (!self::move($source, $destination)) + { + if (!self::move($source, $destination)) + { + return false; + } + } + } + else + { + if (!@move_uploaded_file($source, $destination)) + { + if (!@move_uploaded_file($source, $destination)) + { + return false; + } + } + } + return true; + } + /** * Delete a file. * diff --git a/common/framework/video.php b/common/framework/video.php deleted file mode 100644 index f74d86439..000000000 --- a/common/framework/video.php +++ /dev/null @@ -1,20 +0,0 @@ -'; } else if(/\.(mp4|webm|ogg)$/i.test(result.source_filename)) { - if(result.original_type === 'gif') { + if(result.original_type === 'image/gif') { temp_code += '