title: Codeigniter multiple images upload, get each filename
body: <p>I am using the code below to handle image upload. Every thing is going fine. I have allowed the option to upload two images, one will be the logo and another the screenshot.</p>
  
  <p>Now when I am providing the option to edit the uploads, say choose new files to upload and replace the old ones, I am having this problem.</p>
  
  <p>In my <code>images[]</code> array, I will get the image names one by one with the help of loop. However when the user wants to change the second image(screenshot) and selects nothing in the logo field, only screenshot should be changed.</p>
  
  <p>But in the <code>images[]</code> array, the first element will be the first from the uploads. If i select both the images it is all right, I will get logo.jpg in <code>images[0]</code> and screenshot.jpg in <code>images[1]</code>. But when I select only the second image, i will get screenshot.jpg in <code>images[0]</code>. However, the first element of the array should be blank and the second element of the array should have the data of the second image upload option so the the changes to take into effect. How can i acheive that?</p>
  
  <pre class="lang-php prettyprint-override"><code>$config['upload_path'] = '../uploads/';
              $config['allowed_types'] = '*';
              $config['max_size'] = '0';
              $config['max_width']  = '0';
              $config['max_height']  = '0';
  
              $this-&gt;load-&gt;library('upload', $config);
              $image = array();
              foreach ($_FILES as $key =&gt; $value) {
  
                  if (!empty($value['tmp_name'])) {
  
                      if ( ! $this-&gt;upload-&gt;do_upload($key)) {
                          $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors());
                          //failed display the errors
                      } else {
                          //success
                          $data =  $this-&gt;upload-&gt;data();
                              $image[]= $data['file_name'];
                      }
  
                  }
             }
  </code></pre>