File Uploads

Can anyone shed some light on how to upload images in Yii2. In my view I have

    <?= $form->field($model, 'image_input')->fileInput() ?>

in my controller I have

            $image = new UploadedFile;

            $image->getInstance($model, 'image_input');



but all I get from the var_dump is


public ‘name’ => null

public ‘tempName’ => null

public ‘type’ => null

public ‘size’ => null

public ‘error’ => null

I figured this out. I will add the solution in case others run into the same problem. First of all the forms enctype must be changed to multipart/form-data

<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>

Second of all yii\web\UploadedFile::getInstance() is a static method not a public method, and it has to be called like that. The documentation is a bit misleading.

            $image = UploadedFile::getInstance($model, 'image_input');

            $upload_path = Yii::$app->getBasePath().'/uploads/'.$image->name;



The above uploads the file into an uploads folder I created.