title: Yii2 save image to database as base64
body: <p>I am trying to save image as a base64 into database. But when I submit form I am getting the image NULL. I couldn't understand what's wrong.</p>
  
  <h1>VIEW:</h1>
  
  <pre><code>&lt;div class="content"&gt;
                  &lt;?php $form = ActiveForm::begin([
                      'id' =&gt; 'products-add-form',
                      'action' =&gt; ['products/product-add-form'],
                      'method' =&gt; 'post',
                      'options' =&gt; [
                          'class' =&gt; 'products-tbl-style',
                          'enctype' =&gt; 'multipart/form-data',
                      ]
                  ]); ?&gt;
                  &lt;?= $form-&gt;field($model, 'productName'); ?&gt;
                  &lt;?= $form-&gt;field($model, 'cost'); ?&gt;
                  &lt;?= $form-&gt;field($model, 'available')-&gt;dropDownList(['Y' =&gt; 'Yes', 'N' =&gt; 'No']); ?&gt;
                  &lt;?= $form-&gt;field($model, 'image')-&gt;fileInput(['class'=&gt;'btn btn-primary']); ?&gt;
                  &lt;?= Html::submitButton('Save', ['class'=&gt;'btn btn-success products-save-btn']); ?&gt;
                  &lt;?php ActiveForm::end(); ?&gt;
              &lt;/div&gt;
  </code></pre>
  
  <h1>Controller:</h1>
  
  <pre><code>if($model-&gt;load(Yii::$app-&gt;request-&gt;post())){
      $file = UploadedFile::getInstance($model,'image');
      var_dump($file-&gt;name);
      var_dump($file);
      var_dump($_FILES);
  }
  </code></pre>
  
  <h1>Model:</h1>
  
  <pre><code>public function rules()
      {
          return [
              [['productName', 'cost', 'available', 'image'], 'required'],
              [['cost'], 'number'],
              [['available'], 'string', 'max' =&gt; 1],
              [['image'], 'string'],
              [['productName'], 'string', 'max' =&gt; 100]
          ];
      }
  </code></pre>
  
  <p>Here my JQuery code, I am submitting the form data via ajax, does it cause a problem?</p>
  
  <h1>JS:</h1>
  
  <pre><code>$("form#products-add-form").on('beforeSubmit', function(e){
      var form = $(this);
      $.post(
          form.attr('action'),
          form.serialize()
          )
          .done(function(result){
              if(result == 1){
                  form.trigger("reset");
                  $.pjax.reload({container:'#products-table'});
                  $.notify({
                      icon: "pe-7s-check",
                      message: "New product is added"
  
                  },{
                      type: type[2],
                      timer: 10,
                      placement: {
                          from: 'top',
                          align: 'right'
                      }
                  });
  
              }
              else {
                  alert(result);
              }
          }).fail(function(){
          console.log("server error");
      });
      return false;
  });
  </code></pre>