title: 2 file upload input fields in one form yii2
body: <p>I have table with 2 columns (pic,pic2) my upload form works for the first file input. name of the picture records into column "pic" and file uploads to the server. How can i extend it to upload 2 files? Help pls </p>
  
  <p><strong>model</strong></p>
  
  <p>public $upload_file;</p>
  
  <pre><code>    public function uploadFile() {
      // get the uploaded file instance
  
      $image = UploadedFile::getInstance($this, 'upload_file');
  
      // if no image was uploaded abort the upload
      if (empty($image)) {
          return false;
      }
      $dir = Yii::getAlias('@frontend' . '/web/' . Yii::$app-&gt;params['fileUploadUrl']).$this-&gt;pic; 
      if (file_exists($dir)) {
          unlink($dir);
      } 
      // generate random name for the file
      $this-&gt;pic = time(). '.' . $image-&gt;extension;
      // the uploaded image instance
      return $image;
  }
  
  public function getUploadedFile() {
      // return a default image placeholder if your source avatar is not found
      $pic = isset($this-&gt;pic) ? $this-&gt;pic : 'default.png';
      $dir = Yii::getAlias('@frontend' . '/web/' . Yii::$app-&gt;params['fileUploadUrl']);
      if (!is_dir($dir)) {
          FileHelper::createDirectory($dir);
      } else {
          return $dir . $pic;            
      }
  
  }
  </code></pre>
  
  <p><strong>action in controller</strong></p>
  
  <pre><code>    public function actionCreate()
  {
      $model = new Blog();
  
      if ($model-&gt;load(Yii::$app-&gt;request-&gt;post())) {
  
          $upload_file = $model-&gt;uploadFile();
  
          if ($model-&gt;validate()) {   
              if($model-&gt;save()) {
  
                  if ($upload_file !== false) {
                      $path = $model-&gt;getUploadedFile();
                      $upload_file-&gt;saveAs($path);
                  }
  
                  return $this-&gt;redirect(['view', 'id' =&gt; $model-&gt;id]);
              }
  
          }
      }
  
      return $this-&gt;render('create', [
          'model' =&gt; $model,
      ]);
  
  }
  </code></pre>
  
  <p><strong>view</strong> </p>
  
  <pre><code>    &lt;?= $form-&gt;field($model, 'upload_file')-&gt;widget(FileInput::classname(), [
      'options' =&gt; ['accept' =&gt; 'image/*'],
  ]); ?&gt;
  &lt;?= $form-&gt;field($model, 'upload_file2')-&gt;widget(FileInput::classname(), [
      'options' =&gt; ['accept' =&gt; 'image/*'],
  ]); ?&gt;
  </code></pre>