title: Multiple File Upload in codeigniter using HTML5 and XHR
body: <p>I'm working on multifile upload using html5 and xhr, as you can see I'm sending requests in loop which is a bad 
  concept but I'm not able to upload files when I send it outside the loop and only the last file gets upoaded. 
  Where am I going wrong?</p>
  
  <pre><code>$('#uploadimg').on('click', function(e) {
  
      var files = document.getElementById('files').files;
  
      var formData = new FormData();
      for (var i = 0; i &lt; files.length; i++) {
          formData.append('file', files[i]);
  
          var xhr = new XMLHttpRequest();
          xhr.open('POST', 'http://localhost/ajaxuploader/upload/uploadimg');
          xhr.onload = function() {
              if (xhr.status === 200) {
                  console.log('all done: ' + xhr.status);
              } else {
                  console.log('Something went terribly wrong...');
              }
          };
  
          xhr.send(formData);
  
      }
  
      // now post a new XHR request
  });
  </code></pre>
  
  <p>Codeigniter </p>
  
  <pre><code>public function uploadimg (){
  
      $config['upload_path'] = FCPATH . 'uploads/' ;
      $config['allowed_types'] = 'gif|jpg|png|jpeg|pdf|doc';
  
      $config['remove_spaces'] = 'TRUE';
  
      $this -&gt; load -&gt; library('upload', $config);
      //$this-&gt;upload-&gt;initialize($config);
  
      foreach ($_FILES as $k =&gt; $f) :
          $this -&gt; upload -&gt; do_upload($k);
      endforeach;
      //$this-&gt;index();
  }
  </code></pre>