public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
$this->files = UploadedFile::getInstance($this, 'image');
if ($this->validate()) {
if ($this->files) {
$name = $this->files->baseName . '.' . $this->files->extension;
$path = Yii::getAlias('@webroot' . '/uploads/') . $name;
$this->files->saveAs($path);
$this->image = $name;
if($this->removeImage) {
$fileRemove = Yii::getAlias('@webroot' . '/uploads/') . $image;
if(file_exists($fileRemove)) {
unlink($fileRemove);
$this->image = '';
}
}
}
return true;
} else {
return false;
}
}