mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-15 22:09:48 +08:00
Fixes #1454: refactored FileValidator.
This commit is contained in:
@@ -177,27 +177,28 @@ class FileValidator extends Validator
|
|||||||
return [$this->tooSmall, ['file' => $file->name, 'limit' => $this->minSize]];
|
return [$this->tooSmall, ['file' => $file->name, 'limit' => $this->minSize]];
|
||||||
} elseif (!empty($this->types) && !in_array(strtolower(pathinfo($file->name, PATHINFO_EXTENSION)), $this->types, true)) {
|
} 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)]];
|
return [$this->wrongType, ['file' => $file->name, 'extensions' => implode(', ', $this->types)]];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case UPLOAD_ERR_INI_SIZE:
|
case UPLOAD_ERR_INI_SIZE:
|
||||||
case UPLOAD_ERR_FORM_SIZE:
|
case UPLOAD_ERR_FORM_SIZE:
|
||||||
return [$this->tooBig, ['file' => $file->name, 'limit' => $this->getSizeLimit()]];
|
return [$this->tooBig, ['file' => $file->name, 'limit' => $this->getSizeLimit()]];
|
||||||
case UPLOAD_ERR_PARTIAL:
|
case UPLOAD_ERR_PARTIAL:
|
||||||
Yii::warning('File was only partially uploaded: ' . $file->name, __METHOD__);
|
Yii::warning('File was only partially uploaded: ' . $file->name, __METHOD__);
|
||||||
return [$this->message, []];
|
break;
|
||||||
case UPLOAD_ERR_NO_TMP_DIR:
|
case UPLOAD_ERR_NO_TMP_DIR:
|
||||||
Yii::warning('Missing the temporary folder to store the uploaded file: ' . $file->name, __METHOD__);
|
Yii::warning('Missing the temporary folder to store the uploaded file: ' . $file->name, __METHOD__);
|
||||||
return [$this->message, []];
|
break;
|
||||||
case UPLOAD_ERR_CANT_WRITE:
|
case UPLOAD_ERR_CANT_WRITE:
|
||||||
Yii::warning('Failed to write the uploaded file to disk: ' . $file->name, __METHOD__);
|
Yii::warning('Failed to write the uploaded file to disk: ' . $file->name, __METHOD__);
|
||||||
return [$this->message, []];
|
break;
|
||||||
case UPLOAD_ERR_EXTENSION:
|
case UPLOAD_ERR_EXTENSION:
|
||||||
Yii::warning('File upload was stopped by some PHP extension: ' . $file->name, __METHOD__);
|
Yii::warning('File upload was stopped by some PHP extension: ' . $file->name, __METHOD__);
|
||||||
return [$this->message, []];
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return null;
|
return [$this->message, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user