title: How to upload multiple files using Yii framework 2.0
body: <p>Working with Yii framework 2.0 I want to be able to upload multiple files. Following Yii 2 <a href="http://www.yiiframework.com/doc-2.0/guide-input-file-upload.html">documentation</a>, under subsection <code>Upload Multiple Files</code> I have the following model.</p>
  
  <pre><code>class Newsletter extends \yii\db\ActiveRecord {
      public $attachment_file;
  
      public function rules()
      {
           return [
                [['attachment_file'], 'file', 'maxFiles' =&gt; 5],
           ];
      }
  
      public function upload() {
  
          if ($this-&gt;validate()) { 
              foreach ($this-&gt;attachment_file as $file) {
                  echo '&lt;pre&gt;'; print_r($file); echo '&lt;/pre&gt;';
              }
              return true;
          } else {
              return false;
          }
      }
  }
  </code></pre>
  
  <p>Below is my view.</p>
  
  <pre><code>&lt;?php use yii\widgets\ActiveForm; ?&gt;
  
  &lt;?php $form = ActiveForm::begin(['options' =&gt; ['enctype' =&gt; 'multipart/form-data']]) ?&gt;
  
  &lt;?= $form-&gt;field($model, 'attachment_file[]')-&gt;fileInput(['multiple' =&gt; true,]) ?&gt;
  
  &lt;button&gt;Submit&lt;/button&gt;
  
  &lt;?php ActiveForm::end() ?&gt;
  </code></pre>
  
  <p>In my controller I have the following code snippet.</p>
  
  <pre><code>if (Yii::$app-&gt;request-&gt;isPost) {
          $model-&gt;attachment_file = UploadedFile::getInstances($model, 'attachment_file');
          if ($model-&gt;upload()) {
              die();
              // file is uploaded successfully
              return;
          }
  }
  </code></pre>
  
  <p>With all the code above I expect I can select multiple files with one input file element. But it is not like what I expect. When I select multiple files with one same input file element and hit Submit I saw only the last selected file. So I start to have doubt about what I am doing. Did I do anything wrong? Or do I need to add input file element several times, one input file element for one uploading file?</p>