title: Codeigniter, uploading multiple files with same name
body: <p>I have an upload form that allows me to add as many files as needed. However when I start trying to upload the files I get an error. </p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>$this-&gt;load-&gt;library('upload'); 
  $error = "";
  $file  = "";
  $this-&gt;total_count_of_files = count($_FILES['user_certificates']['name']);
  print_r($_FILES['user_certificates']['name']);
  
  for($i=0; $i&lt;$this-&gt;total_count_of_files; $i++)
  {
      $_FILES['user_certificates']['name'] = $_FILES['user_certificates']['name'][$i];
      $_FILES['user_certificates']['type'] = $_FILES['user_certificates']['type'][$i];
      $_FILES['user_certificates']['tmp_name'] = $_FILES['user_certificates']['tmp_name'][$i];
      $_FILES['user_certificates']['error'] = $_FILES['user_certificates']['error'][$i];
      $_FILES['user_certificates']['size'] = $_FILES['user_certificates']['size'][$i];
  
      $config['encrypt_name'] = TRUE;
      $config['file_name'] = $_FILES['user_certificates']['name'];
      $config['upload_path'] = './certificate_files/';
      $config['allowed_types'] = 'txt|pdf|doc|docx';
      $config['max_size'] = 0;
  
      $this-&gt;upload-&gt;initialize($config);
  
      if (!$this-&gt;upload-&gt;do_upload())
      {
          $status = 'error';
          $msg = $this-&gt;upload-&gt;display_errors();
      }
      else
      {
          $data = $this-&gt;upload-&gt;data();
          $file = $data['raw_name'] . $data['file_ext'];
      }
      if($file)
      {
          $status = "success";
          $msg = "Image successfully uploaded";
      }
      else
      {
          $status = "error";
          $msg = "Something went wrong when saving the image, please try again.";
      }
  }   
  echo json_encode(array('status' =&gt; $status, 'msg' =&gt; $msg));
  exit();
  </code></pre>
  
  <p>The <code>print_r($_FILES['user_certificates']['name']))</code> shows me the files I have added:</p>
  
  <pre><code>Array ( [0] =&gt; license.txt [1] =&gt; license.txt )
  </code></pre>
  
  <p>I am totally stuck on how to get the upload to work. Any ideas?</p>
  
  <p>Cheers in advance!</p>
  
  <p>EDIT</p>
  
  <p>If I change this:</p>
  
  <pre><code>if (!$this-&gt;upload-&gt;do_upload())
  </code></pre>
  
  <p>to this:</p>
  
  <pre><code>if (!$this-&gt;upload-&gt;do_upload('user_certificates'))
  </code></pre>
  
  <p>it works, but only for one file, it doesn't seem to loop round again for some reason</p>