Trying to get property 'name' of non-object for FileInput

Using kartik FileInput I am doing:

            $webFile = UploadedFile::getInstance($model, 'webFile');
            $tmp = explode(".", $webFile->name);
            $model->Ext = end($tmp);

and receiving the error from the 2nd line

Trying to get property ‘name’ of non-object

what am I missing?

I’m now wondering if the user submitted the form without having selected a file? How would I test that in the code to stop processing?

Check content of $webFile before proceeding further to avoid error as file is not mandatory.

1 Like