In code igniter multiple image update
<p>i do multiple image upload in code igniter the same code is used to update the the multiple image but in the update time i change name  i don't change images then click ok button  the name is update but the images are missing but i change the image the that only update..why?</p>

<p>my controller</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code> function update_products() 
     { 
    $id = $this-&gt;input-&gt;post('id');
    $this-&gt;load-&gt;library('upload');
    $dataInfo = array();
    $files = $_FILES;
    $cpt = count($_FILES['userfile']['name']);
    for($i=0; $i&lt;$cpt; $i++)
    {           
        $_FILES['userfile']['name']= $files['userfile']['name'][$i];
        $_FILES['userfile']['type']= $files['userfile']['type'][$i];
        $_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
        $_FILES['userfile']['error']= $files['userfile']['error'][$i];
        $_FILES['userfile']['size']= $files['userfile']['size'][$i];    

        $this-&gt;upload-&gt;initialize($this-&gt;set_upload_options());
        $this-&gt;upload-&gt;do_upload();
       
           $dataInfo[] = $this-&gt;upload-&gt;data();

    }
   $data = array(
        
         'name' =&gt; $this-&gt;input-&gt;post('name'),
         'prod_image' =&gt; $dataInfo[0]['file_name'],
          'prod_image1' =&gt; $dataInfo[1]['file_name'],
          'prod_image2' =&gt; $dataInfo[2]['file_name'],
         'upadted_time' =&gt; date('Y-m-d H:i:s')  
      );
   
    $stock = array(
     'discount' =&gt; $this-&gt;input-&gt;post('discount'),
    );
                 $this-&gt;db-&gt;where('prod_id', $id);
                $this-&gt;db-&gt;update('tbl_products', $data);
             $this-&gt;db-&gt;where('prods_id', $id);
             $this-&gt;db-&gt;update('otc_product_discount', $stock);
        
                 $this-&gt;session-&gt;set_flashdata('msg','&lt;div class="alert alert-success text-center"&gt;You are Successfully updated!&lt;/div&gt;');
      redirect('index.php/admin/display_product_list');
                 
  }         
    }  </code></pre>
</div>
</div>
</p>

<p>my view </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code> &lt;label for="type"&gt;Product Image&lt;/label&gt;
&lt;img src="&lt;?php echo base_url("./resources/images/products/");  if($row-&gt;prod_image) echo $row-&gt;prod_image; else echo "no-img.jpg"; ?&gt;" alt="" height="50" width="50"/&gt;
&lt;input type="file" id="med_img" class="file_upload"  name="userfile[]" value="&lt;?php  echo $row-&gt;prod_image; ?&gt;" /&gt; 

&lt;label for="type"&gt;Product Image2&lt;/label&gt;
&lt;img src="&lt;?php echo base_url("./resources/images/products/");  if($row-&gt;prod_image1) echo $row-&gt;prod_image1; else echo "no-img.jpg"; ?&gt;" alt="" height="50" width="50"/&gt;
&lt;input type="file" id="med_img" class="file_upload"  name="userfile[]" value="&lt;?php  echo $row-&gt;prod_image1; ?&gt;" /&gt;
&lt;label for="type"&gt;Product Image3&lt;/label&gt;
&lt;img src="&lt;?php echo base_url("./resources/images/products/");  if($row-&gt;prod_image2) echo $row-&gt;prod_image2; else echo "no-img.jpg"; ?&gt;" alt="" height="50" width="50"/&gt;
                  &lt;input type="file" id="med_img" class="file_upload"  name="userfile[]" value="&lt;?php  echo $row-&gt;prod_image2; ?&gt;" /&gt;
            </code></pre>
</div>
</div>
</p>

<p>uplaod function is</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>private function set_upload_options()
{   
    //upload an image options
    $config = array();
    $config['upload_path'] = './resources/images/products/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']      = '0';
    $config['overwrite']     = FALSE;

    return $config;
}</code></pre>
</div>
</div>
</p>