From 72db6ffb1a40ece354aeca0df8cb85840a2eb3d1 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sat, 7 Dec 2013 00:10:08 -0500 Subject: [PATCH] Fixes #1454: refactored FileValidator. --- framework/yii/validators/FileValidator.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/framework/yii/validators/FileValidator.php b/framework/yii/validators/FileValidator.php index 2e6a544..942bf1e 100644 --- a/framework/yii/validators/FileValidator.php +++ b/framework/yii/validators/FileValidator.php @@ -177,27 +177,28 @@ class FileValidator extends Validator return [$this->tooSmall, ['file' => $file->name, 'limit' => $this->minSize]]; } elseif (!empty($this->types) && !in_array(strtolower(pathinfo($file->name, PATHINFO_EXTENSION)), $this->types, true)) { return [$this->wrongType, ['file' => $file->name, 'extensions' => implode(', ', $this->types)]]; + } else { + return null; } - break; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: return [$this->tooBig, ['file' => $file->name, 'limit' => $this->getSizeLimit()]]; case UPLOAD_ERR_PARTIAL: Yii::warning('File was only partially uploaded: ' . $file->name, __METHOD__); - return [$this->message, []]; + break; case UPLOAD_ERR_NO_TMP_DIR: Yii::warning('Missing the temporary folder to store the uploaded file: ' . $file->name, __METHOD__); - return [$this->message, []]; + break; case UPLOAD_ERR_CANT_WRITE: Yii::warning('Failed to write the uploaded file to disk: ' . $file->name, __METHOD__); - return [$this->message, []]; + break; case UPLOAD_ERR_EXTENSION: Yii::warning('File upload was stopped by some PHP extension: ' . $file->name, __METHOD__); - return [$this->message, []]; + break; default: break; } - return null; + return [$this->message, []]; } /**