title: Multiple files upload (Array) with CodeIgniter 2.0
body: <p>I've been searching and struggling for 3 days now to make this works but I just can't.
  What I want to do is use a Multiple file input form and then upload them. I can't just use a fixed number of file to upload. I tried many many solutions on StackOverflow but I wasn't able to find a working one.</p>
  
  <p>Here's my Upload controller</p>
  
  <pre><code>&lt;?php
  
  class Upload extends CI_Controller {
  
  function __construct()
  {
      parent::__construct();
      $this-&gt;load-&gt;helper(array('form', 'url','html'));
  }
  
  function index()
  {    
      $this-&gt;load-&gt;view('pages/uploadform', array('error' =&gt; ' ' ));
  }
  
  function do_upload()
  {
      $config['upload_path'] = './Images/';
      $config['allowed_types'] = 'gif|jpg|png';
  
  
      $this-&gt;load-&gt;library('upload');
  
   foreach($_FILES['userfile'] as $key =&gt; $value)
      {
  
          if( ! empty($key['name']))
          {
  
              $this-&gt;upload-&gt;initialize($config);
  
              if ( ! $this-&gt;upload-&gt;do_upload($key))
              {
                  $error['error'] = $this-&gt;upload-&gt;display_errors();
  
                  $this-&gt;load-&gt;view('pages/uploadform', $error);
              }    
              else
              {
                  $data[$key] = array('upload_data' =&gt; $this-&gt;upload-&gt;data());
  
                  $this-&gt;load-&gt;view('pages/uploadsuccess', $data[$key]);
  
  
              }
           }
  
      }    
    }    
   }
   ?&gt; 
  </code></pre>
  
  <p>My upload form is This.</p>
  
  <pre><code> &lt;html&gt;
   &lt;head&gt;
      &lt;title&gt;Upload Form&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;?php echo $error;?&gt;
  
  &lt;?php echo form_open_multipart('upload/do_upload');?&gt;
  
  &lt;input type="file" multiple name="userfile[]" size="20" /&gt;
  &lt;br /&gt;&lt;br /&gt;
  
  
  &lt;input type="submit" value="upload" /&gt;
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>I just keep having this error :</p>
  
  <blockquote>
    <p>You did not select a file to upload.</p>
  </blockquote>
  
  <p>Here's the array of the example: </p>
  
  <blockquote>
    <p>Array ( [userfile] => Array ( [name] => Array ( [0] => youtube.png [1] => zergling.jpg ) [type] => Array ( [0] => image/png [1] => image/jpeg ) [tmp_name] => Array ( [0] => E:\wamp\tmp\php7AC2.tmp [1] => E:\wamp\tmp\php7AC3.tmp ) [error] => Array ( [0] => 0 [1] => 0 ) [size] => Array ( [0] => 35266 [1] => 186448 ) ) )</p>
  </blockquote>
  
  <p>I have this like 5 times in a row if I select 2 files.
  I also use the standard Upload library.</p>