public function upload()
    {
        if (!$this->validate()) {
            return false;
        }

        try {
            $save_path = Yii::getAlias($this->_uploadDir);
            FileHelper::createDirectory($save_path);

            $image = $this->image->baseName . '.' . $this->image->extension;

            if (!$this->image->saveAs(FileHelper::normalizePath($save_path . '/' . $image))) {
                return false;
            }

            $this->path = Yii::getAlias($save_path . '/' . $image);
            $this->url = Yii::getAlias($this->_viewPath . '/' . $image);

            return true;

        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }

        return false;
    }
public function upload()
    {
        if (!$this->validate()) {
            return false;
        }

        try {
            $save_path = Yii::getAlias($this->_uploadDir);
            FileHelper::createDirectory($save_path);

            $image = $this->image->baseName . '.' . $this->image->extension;

            if (!$this->image->saveAs(FileHelper::normalizePath($save_path . '/' . $image))) {
                return false;
            }

            $this->path = Yii::getAlias($save_path . '/' . $image);
            $this->url = Yii::getAlias($this->_viewPath . '/' . $image);

            return true;

        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }

        return false;
    }
public function upload ( ) { if ( ! $ this -> validate ( ) ) { return false ; } try { $ save_path = Yii :: getAlias ( $ this -> _uploadDir ) ; FileHelper :: createDirectory ( $ save_path ) ; $ image = $ this -> image -> baseName . '.' . $ this -> image -> extension ; if ( ! $ this -> image -> saveAs ( FileHelper :: normalizePath ( $ save_path . '/' . $ image ) ) ) { return false ; } $ this -> path = Yii :: getAlias ( $ save_path . '/' . $ image ) ; $ this -> url = Yii :: getAlias ( $ this -> _viewPath . '/' . $ image ) ; return true ; } catch ( Exception $ e ) { Yii :: error ( $ e -> getMessage ( ) ) ; } return false ; }
Validates and saves the image.
Creates the folder to store images if necessary.
@return bool
Validates and saves the image . Creates the folder to store images if necessary .