public function upload() { if ($this->validate()) { $dir = Yii::getAlias('@frontend/web/images/articles'); $imagable = \Yii::$app->articles_imagable; $imagable->imagesPath = Yii::getAlias('@frontend/web/images/articles'); $image_name = []; /** @var Imagable $this */ if (!empty($this->social)) { $this->social->saveAs($dir . $this->social->baseName . '.jpg'); $image_name['social'] = $imagable->create('social', $dir . $this->social->baseName . '.jpg'); unlink($dir . $this->social->baseName . '.jpg'); } /** @var Imagable $this */ if (!empty($this->thumbnail)) { $this->thumbnail->saveAs($dir . $this->thumbnail->baseName . '.jpg'); $image_name['thumbnail'] = $imagable->create('thumbnail', $dir . $this->thumbnail->baseName . '.jpg'); unlink($dir . $this->thumbnail->baseName . '.jpg'); } /** @var Imagable $this */ if (!empty($this->menu_item)) { $this->menu_item->saveAs($dir . $this->menu_item->baseName . '.jpg'); $image_name['menu_item'] = $imagable->create('menu_item', $dir . $this->menu_item->baseName . '.jpg'); unlink($dir . $this->menu_item->baseName . '.jpg'); } return $image_name; } else { return false; } }
public function upload() { if ($this->validate()) { $imagable = \Yii::$app->shop_imagable; $dir = $imagable->imagesPath . '/shop-product/'; if (!empty($this->image)) { if (!file_exists($dir)) { BaseFileHelper::createDirectory($dir); } $newFile = $dir . $this->image->name; if ($this->image->saveAs($newFile)) { $image_name = $imagable->create('shop-product', $newFile); unlink($newFile); return $image_name; } else { throw new Exception('Image saving failed.'); } } } return false; }