title: Uploading multiple file using codeigniter
body: <p>I got a problem with multiple upload file using codeigniter. I've tried many method before but still no success. </p>
  
  <p>Here is my code.</p>
  
  <p><strong>View</strong></p>
  
  <pre><code>&lt;?php echo form_open_multipart('staff/upload_files', array('id' =&gt; 'form_checkbox')); ?&gt;
  </code></pre>
  
  <p><strong>Inside table:</strong></p>
  
  <pre><code>     &lt;tr&gt;
          &lt;th width="20%"&gt;Select File :&lt;/th&gt;
          &lt;td&gt;
              &lt;input type="file" name="userfile[]" value="" /&gt;&amp;nbsp;&lt;span class="green"&gt;[Max File Upload: 2MB]&lt;/span&gt;&lt;br&gt;
              &lt;input type="file" name="userfile[]" value="" /&gt;&amp;nbsp;&lt;span class="green"&gt;[Max File Upload: 2MB]&lt;/span&gt;&lt;br&gt;
              &lt;input type="file" name="userfile[]" value="" /&gt;&amp;nbsp;&lt;span class="green"&gt;[Max File Upload: 2MB]&lt;/span&gt; 
          &lt;/td&gt;
      &lt;/tr&gt;
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>    function upload_files() {
          $data['studentid'] = $studentid;
          if ($this-&gt;input-&gt;post('submit')) {
  
              $config['upload_path'] = './upload/announcement/collegecode/';
              $config['allowed_types'] = 'jpg|png';
              $config['max_size'] = '2048';
              $config['max_width'] = '0';
              $config['max_height'] = '0';
              $config['overwrite'] = FALSE;
  
              $this-&gt;load-&gt;library('upload', $config);
              if (!$this-&gt;upload-&gt;do_upload()) {
                  $this-&gt;session-&gt;set_flashdata('msg', 'error: ' . $this-&gt;upload-&gt;display_errors());
              } else {
                  $this-&gt;session-&gt;set_flashdata('msg', 'success:Successfully Upload Student Photo');
              }
          }
  
          $this-&gt;template-&gt;load('template', 'staff/announcement', $data);
      }
  </code></pre>
  
  <p>I've also tried this method, but no file was uploaded.</p>
  
  <pre><code>$config['upload_path'] = './upload/announcement/collegecode/';
          $path=$config['upload_path'];
          $config['allowed_types'] = 'gif|jpg|jpeg|png';
          $config['max_size'] = '2048';
          $config['max_width'] = '1920';
          $config['max_height'] = '1280';
          $this-&gt;load-&gt;library('upload');
  
          foreach ($_FILES as $key =&gt; $value)
          {
  
  
              if (!empty($key['userfile']))
              {
  
  
                  $this-&gt;upload-&gt;initialize($config);
                  if (!$this-&gt;upload-&gt;do_upload($key))
                  {
  
                      $errors = $this-&gt;upload-&gt;display_errors();
  
  
                      flashMsg($errors);
  
                  }
                  else
                  {
                       // Code After Files Upload Success GOES HERE
                  }
              }
          }
  </code></pre>