Skip to content

Commit

Permalink
Update FileValidator.php
Browse files Browse the repository at this point in the history
Implementation of yiisoft#8995
  • Loading branch information
PowerGamer1 committed Jul 3, 2015
1 parent f37c6dd commit 4f25734
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions framework/validators/FileValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class FileValidator extends Validator
/**
* @var integer the maximum file count the given attribute can hold.
* It defaults to 1, meaning single file upload. By defining a higher number,
* multiple uploads become possible.
* multiple uploads become possible. Setting it to 0 means there is no limit on
* the amount of files that can be uploaded.
* @see tooMany for the customized message when too many files are uploaded.
*/
public $maxFiles = 1;
Expand Down Expand Up @@ -168,7 +169,7 @@ public function init()
*/
public function validateAttribute($model, $attribute)
{
if ($this->maxFiles > 1) {
if ($this->maxFiles != 1) {
$files = $model->$attribute;
if (!is_array($files)) {
$this->addError($model, $attribute, $this->uploadRequired);
Expand All @@ -184,7 +185,7 @@ public function validateAttribute($model, $attribute)
if (empty($files)) {
$this->addError($model, $attribute, $this->uploadRequired);
}
if (count($files) > $this->maxFiles) {
if ($this->maxFiles && count($files) > $this->maxFiles) {
$this->addError($model, $attribute, $this->tooMany, ['limit' => $this->maxFiles]);
} else {
foreach ($files as $file) {
Expand Down

0 comments on commit 4f25734

Please sign in to comment.