Error Call to a member function saveAs() on null

hi guys, i’m new on yii and i’m tying to upload files into my database and i hathis error
(i’m using the basic version of yii)

and this is my code for the controller:

public function actionCreate()
$model = new Descriptif();

    if ($model->load(Yii::$app->request->post())) {

        $image = $model -> entreprise;
        $model -> file = UploadedFile::getInstance($model,'sujet');

        $model -> file -> saveAs('/uploads/'.$image.'.'.$model -> file -> extension);
        $model -> sujet = '/uploads/'.$file->baseName.'.'.$model -> file -> extension;

        return $this->redirect(['view', 'id' => $model->NumDescriptif]);

    return $this->render('create', [
        'model' => $model,

if you have any idea please help me
if you want any more details ask me about

Thank you guys

thank you

“Call to a member function saveAs() on null” means that $model->file is null, and it indicates the failure of UploadedFile::getInstance().

You have to validate the user input before you call UploadedFile::getInstance() as you see in the Guide > Uploading Files (