title: Set image maximum file size with validator
body: <p>I am implementing image upload in Yii2 using File Input Widget as shown in <a href="http://demos.krajee.com/widget-details/fileinput" rel="noreferrer">http://demos.krajee.com/widget-details/fileinput</a>. May I know how to set the uploaded file size limit?</p>
  
  <p>I have added: </p>
  
  <pre><code>['image', 'file', 'extensions' =&gt; ['png', 'jpg', 'gif'], 'maxSize' =&gt; 1024 * 1024 * 1024],
  </code></pre>
  
  <p>inside the model's <code>rules()</code> but it does not seem to work.</p>
  
  <p>Hope someone can advise. Thanks. </p>
  
  <p>In View:</p>
  
  <pre><code>&lt;?php $form = ActiveForm::begin(['enableClientValidation' =&gt; false,  'options' =&gt; [ 'enctype' =&gt; 'multipart/form-data']]); ?&gt;
  
  
  &lt;?php
  
  echo $form-&gt;field($model, 'image')-&gt;widget(FileInput::classname(), [
      'options'=&gt;['accept'=&gt;'image/*', 'multiple'=&gt;true],
      'pluginOptions'=&gt;['allowedFileExtensions'=&gt;['jpg', 'jpeg', 'gif','png']]
  ]);
  
  ?&gt;
  
  &lt;?php ActiveForm::end(); ?&gt;
  </code></pre>
  
  <p>In Controller:</p>
  
  <pre><code>    $model = new IMAGEMODEL();  
  
      Yii::$app-&gt;params['uploadPath'] = Yii::$app-&gt;basePath . '/web/uploads/PROJECT/';
  
  
      if ($model-&gt;load(Yii::$app-&gt;request-&gt;post())) {
          // get the uploaded file instance. for multiple file uploads
          // the following data will return an array
          $image = UploadedFile::getInstance($model, 'image');
  
  
          // store the source file name
          $model-&gt;FILENAME = $image-&gt;name;
          $ext = end((explode(".", $image-&gt;name)));
  
          // generate a unique file name
  
          $model-&gt;AVATAR = Yii::$app-&gt;security-&gt;generateRandomString().".{$ext}";
          $model-&gt;STD_ID=$_POST['IMAGEMODEL']['STD_ID'];
  
  
          // the path to save file, you can set an uploadPath
          // in Yii::$app-&gt;params (as used in example below)
          $path = Yii::$app-&gt;params['uploadPath'] . $model-&gt;AVATAR;
  
          if($model-&gt;save()){
              $image-&gt;saveAs($path);
              Yii::$app-&gt;session-&gt;setFlash('success', 'Image uploaded successfully');
              return $this-&gt;redirect(['view', 'id'=&gt;$id]);
  
          } else {
              Yii::$app-&gt;session-&gt;setFlash('error', 'Fail to save image');
          }
      }
  </code></pre>
  
  <p>In Model:</p>
  
  <pre><code>public function rules()
  {
      return [
          [['STD_ID', 'FILENAME'], 'required'],
          [['FILENAME'], 'string'],
          [['LAST_UPD_ON'], 'safe'],
          [['STD_ID'], 'string', 'max' =&gt; 50],
          [['LAST_UPDATE_BY'], 'string', 'max' =&gt; 150],
  
          [['image', 'FILENAME'], 'safe'],
          ['image', 'file', 'extensions' =&gt; ['png', 'jpg', 'gif'], 'maxSize' =&gt; 1024 * 1024 * 1],
  
      ];
  }
  </code></pre>