Yii2 FileInput - File not saved into the server
<p><a href="https://i.stack.imgur.com/BpJkQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BpJkQ.png" alt="screenshot"></a></p>

<p>i am using Yii2 and Kartik's FileInput extension. and I am having issues with it saving to the directory. I am using the yii-advanced template, and generate the CRUD codes using gii. Currently editing it as I go.</p>

<p>When I save it it refused to save and show the "Please upload a file" message.</p>

<p>Files that will be saved with be .doc and .pdf mostly.</p>

<p>If I set the 'skipOnEmpty = True' in the model, it will save the form but not the file.</p>

<p>Datatype on my mysql table is set to VARCHAR because I want to save its path only.</p>

<p>I followed this guide - <a href="http://webtips.krajee.com/upload-file-yii-2-using-fileinput-widget/" rel="nofollow noreferrer">http://webtips.krajee.com/upload-file-yii-2-using-fileinput-widget/</a></p>

<p>Here is my model;</p>

<pre><code>&lt;?php

namespace app\models;

use Yii;

class FormMovement extends \yii\db\ActiveRecord
{

    public static function tableName()
    {
        return 'form_movement';
    }

    public function rules()
    {
        return [
            [['fm_date_received', 'fm_form_name', 'fm_from', 'fm_ptj'], 'required'],
            [['form_id'], 'integer'],
            [['fm_date_received', 'fm_date_action1', 'fm_date_action2'], 'safe'],
            [['fm_form_name', 'fm_note'], 'string', 'max' =&gt; 500],
            [['fm_from', 'fm_ptj', 'fm_action1', 'fm_action2'], 'string', 'max' =&gt; 100],
            [['fm_upload'], 'file', 'skipOnEmpty' =&gt; false, 'extensions'=&gt;'jpg,pdf,png,doc,docx,xls,xlsx'],
        ];
    }

}
</code></pre>

<p>Then here is my controller(i included only the upload function, but it is the rest with the generated codes(CRUD actions),</p>

<pre><code>&lt;?php

namespace frontend\controllers;

use Yii;
use app\models\FormMovement;
use app\models\SearchFormMovement;
//use app\models\FormType;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;

class FormMovementController extends Controller
{
public function actionUpload()
{
    $model = new FormMovement;
    if ($model-&gt;load(Yii::$app-&gt;request-&gt;post())) {
        $file = UploadedFile::getInstance($model, 'fm_upload');

        // store the source file name
        $model-&gt;fm_upload = $file-&gt;name;
        $ext = end((explode(".", $file-&gt;name)));

        $model-&gt;fm_upload = Yii::$app-&gt;security-&gt;generateRandomString().".{$ext}";

        $path = Yii::$app-&gt;params['uploadPath'] . $model-&gt;fm_upload;;

        if($model-&gt;save()){
            $file-&gt;saveAs($path);
            return $this-&gt;redirect(['view', 'id'=&gt;$model-&gt;_id]);
        } else {
            // error in saving model
        }
    }
    return $this-&gt;render('create', [
        'model'=&gt;$model,
    ]);
}
}
</code></pre>

<p>and this is my view, also the same like Controller. Codes are only the upload part.</p>

<pre><code>&lt;?php

use yii\helpers\Html;
use kartik\date\DatePicker;
//use app\models\FormMovement;
use app\models\FormType;
use yii\bootstrap\ActiveField;
use kartik\form\ActiveForm;
use kartik\file\FileInput;

/* @var $this yii\web\View */
/* @var $model app\models\FormMovement */
/* @var $form yii\widgets\ActiveForm */
?&gt;

&lt;div class="form-movement-form"&gt;

    &lt;?php $form = ActiveForm::begin([![\[][1]][1]
        'type' =&gt; ActiveForm::TYPE_HORIZONTAL,
        'formConfig' =&gt; ['labelSpan' =&gt; 3, 'deviceSize' =&gt; ActiveForm::SIZE_SMALL], 
        'options' =&gt; ['enctype' =&gt; 'multipart/form-data']
    ]); ?&gt;
&lt;div class="form-group kv-fieldset-inline"&gt;
        &lt;?= Html::activeLabel($model, 'fm_upload', [
                'label'=&gt;'MUAT NAIK FAIL',
                'class'=&gt;'col-sm-1 control-label'
            ]) ?&gt;

        &lt;div class="col-sm-8"&gt;
        &lt;?= $form-&gt;field($model, 'fm_upload',[
                    'showLabels'=&gt;false
                ])-&gt;widget(FileInput::classname(), [
                'options' =&gt; ['accept' =&gt; 'image/*'],
                'pluginOptions'=&gt;['allowedFileExtensions'=&gt;['jpg','pdf','png','doc','docx','xls','xlsx']
        ]]) ?&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div class="form-group"&gt;
        &lt;?= Html::submitButton($model-&gt;isNewRecord ? 'Create' : 'Update', ['class' =&gt; $model-&gt;isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?&gt;
    &lt;/div&gt;
</code></pre>

<p>Hope I have provided enough info. Appreciate any help.</p>

<p>EDIT: Here is what the logs looks like, I think its the validation issue but I can't really figure out which one is causing it, the model or the controller.</p>

<p><a href="https://i.stack.imgur.com/NAsqB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NAsqB.png" alt="SO2"></a></p>