public function deleteImage() { foreach (['source', 'big', 'mid'] as $type) { $path = $this->{"path_to_{$type}"}; if (strlen($path)) { FileHelper::unlink(static::getAbsPath($path)); } $this->{"path_to_{$type}"} = null; } }
public function save() { $model = parent::save(); if (strlen($this->upload_key)) { if ($this->upload_key == '__clear__') { $model->deleteImage(); $model->save(); } else { $path = \app\helpers\Upload::getTmpUploadPath($this->upload_key); if (is_file($path)) { $model->pullImage($path); $model->save(); FileHelper::unlink($path); } } } return $model; }