From c20720e3666cea4dd87b5554426e2544952403fc Mon Sep 17 00:00:00 2001 From: Jovanni Lo Date: Mon, 4 Feb 2019 08:14:20 +0800 Subject: [PATCH] fix validations --- src/File.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/File.php b/src/File.php index 1a2739a..ab368ce 100644 --- a/src/File.php +++ b/src/File.php @@ -242,12 +242,18 @@ public function validate() { // filter extension if ($this->_validations['extensions']) { + $extensions = $this->_validations['extensions']; $def_ext_filter = [ 'is' => [], 'not' => [], 'message' => '[extension: '.$this->extension.'] '.$this->_error_messages[self::UPLOAD_ERR_EXTENSION_FILTER] ]; - $ext_filter = Util::set_values($def_ext_filter, $this->_validations['extensions'], 'is'); + + if (is_array($extensions) && is_int(key($extensions))) { + $extensions['is'] = $extensions; + } + + $ext_filter = Util::set_values($def_ext_filter, $extensions, 'is'); $this->set_error_message(self::UPLOAD_ERR_EXTENSION_FILTER, $ext_filter['message']); if (!is_array($ext_filter['is'])) $ext_filter['is'] = [$ext_filter['is']]; @@ -260,13 +266,19 @@ public function validate() { // filter category if ($this->_validations['categories']) { + $categories = $this->_validations['categories']; + $def_cat_filter = [ 'is' => [], 'not' => [], 'message' => '[category: '.$this->category.'] '.$this->_error_messages[self::UPLOAD_ERR_CATEGORY_FILTER] ]; - $cat_filter = Util::set_values($def_cat_filter, $this->_validations['categories'], 'is'); + if (is_array($categories) && is_int(key($categories))) { + $categories['is'] = $categories; + } + + $cat_filter = Util::set_values($def_cat_filter, $categories, 'is'); $this->set_error_message(self::UPLOAD_ERR_CATEGORY_FILTER, $cat_filter['message']); if (!is_array($cat_filter['is'])) $cat_filter['is'] = [$cat_filter['is']];