yii-dream-team/yii2-upload-behavior

Please, add this to your good extension

Closed this issue · 1 comments

class CustomImageUploadBehavior extends ImageUploadBehavior
{

/**
 * @var bool
 */
public $deleteTempFile = true;

/**
 * @throws Exception
 */
public function afterSave()
{
    if ($this->file instanceof UploadedFile) {
        $path = $this->getUploadedFilePath($this->attribute);
        FileHelper::createDirectory(pathinfo($path, PATHINFO_DIRNAME), 0775, true);
        if (!$this->file->saveAs($path, $this->deleteTempFile)) {
            throw new Exception('File saving error.');
        }
        $this->owner->trigger(static::EVENT_AFTER_FILE_SAVE);
    }
}

}

Thank you for suggestions, this code FileUploadBehavior.php