Trying to get property 'baseName' of non-object


(SomebodyHere) #1

In my model (a form) I have:

    public $cover;
    public $pfp;

...
            ['cover', 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg'],
            ['pfp', 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg'],

            $coo = new AmazonS3();
            if ($this->cover)
            {
                $cov = $coo->putObject(
                    $time . $this->cover->baseName . '.' . $this->cover->extension,
                    $this->cover->tempName,
                    'public-read'
                );
                $col = $coo->deleteObject($profile->cover);
                $user->cover = $time . $this->cover->baseName . '.' . $this->cover->extension;
            }
            if ($this->pfp)
            {
                $pfp = $coo->putObject(
                    $time . $this->pfp->baseName . '.' . $this->pfp->extension,
                    $this->pfp->tempName,
                    'public-read'
                );
                $col = $coo->deleteObject($profile->pfp);
                $user->pfp = $time . $this->pfp->baseName . '.' . $this->pfp->extension;
            }

but when I try uploading I get the error Trying to get property 'baseName' of non-object. There is in reality an object already uploaded, but why is this not working?

Controller:

if ($model->load(Yii::$app->request->post())) 
        {
            $model->cover = UploadedFile::getInstance($model, 'cover');
            $model->pfp = UploadedFile::getInstance($model, 'pfp');
            
            if ($model->editProfile()) {
                
                return $this->redirect(['/site/index']);
            }
        }

(SomebodyHere) #2

Nevermind, I figured out the problem. I was calling trim on the files, which messed up everything.