dosamigos\fileupload\actions\AbstractUploadAction::upload PHP Method

upload() protected method

Handles files upload Override as needed.
protected upload ( ActiveRecord $model ) : mixed
$model yii\db\ActiveRecord
return mixed
    protected function upload($model)
    {
        /** @var UploadedFile $file */
        $file = $model->{$this->fileAttributeName};
        $path = Yii::getAlias($this->filePathAlias);
        $filename = md5(mt_rand()) . "-{$file->baseName}.{$file->extension}";
        if (!$file->saveAs($path . '/' . $filename)) {
            throw new Exception(Yii::t('fileupload', 'Cannot save uploaded file'));
        }
        $model->{$this->urlAttributeName} = $this->filesWebUrl . '/' . $filename;
        // thumbnail url is the same as the url. Extend from this class and override this method
        // to implement your thumbnail logic.
        $model->{$this->thumbnailUrlAttributeName} = $model->{$this->urlAttributeName};
        if (!$model->save(false)) {
            @unlink($path . '/' . $filename);
            throw new Exception(Yii::t('fileupload', 'Cannot save file model.'));
        }
    }