public function uploadFile()
{
$this->filename = $this->file->baseName . '.' . $this->file->extension;
$this->avatar = Yii::$app->security->generateRandomString() . '.' . $this->file->extension;
$this->type = $this->file->type;
if ($this->validate()) {
$this->save(false);
$filePath = Yii::$app->params['imagePath'] . $this->avatar;
$image = new ImageResize($this->file->tempName);
if ($image->getSourceWidth() > 1200) {
$image->resizeToWidth(1200)->save($filePath);
} else {
$this->file->saveAs($filePath);
}
return true;
}
return false;
}