title: how can fix error looping after rename file on codeigniter
body: <p>I created a new function to change the name of the file to be uploaded. Now I have successfully changed the file name. but in my code, before it loops through the files normally it gives an error.</p>
  
  <p>I have 5 files inputs where the input is in 1 form.</p>
  
  <p>There was no problems before adding my function, but after adding the rename function, my loop became messy, but my old code was working correctly.</p>
  
  <p>here is my old code:</p>
  
  <pre><code>public function proses_upload()
  {
  
      $gambar = array();
      $jumlah = count($_FILES['userfile']['name']);
  
      for ($i=0; $i &lt; $jumlah; $i++) 
      { 
          $file_name = $_FILES['userfile']['name'][$i];
          $tmp_name = $_FILES['userfile']['tmp_name'][$i];        
          move_uploaded_file($tmp_name, "file/".$file_name);
          $gambar[$i] = $file_name;                 
      }
  
      $nama_file1 = $gambar[0];
      $format_p2ptm =1; 
      $tanggal = date("Y-m-d H:i:s");
      $jenis ='p2ptm';
  
      $nama_file2 = $gambar[1];
      $format_p2ptm2 =2; 
      $jenis ='p2ptm';
  
      $nama_file3 = $gambar[2];
      $format_p2ptm3 =3;
      $jenis ='p2ptm';
  
      $nama_file4 = $gambar[3];
      $format_p2ptm4 =4;
      $jenis ='p2ptm';
  
      $nama_file5 = $gambar[4];
      $format_p2ptm5 =5; 
      $jenis ='p2ptm';
  
      if (!$nama_file1 == "") {
          $this-&gt;app_model-&gt;insert_data('penyakit', $format_p2ptm, $tanggal,$nama_file1,$jenis, $this-&gt;session-&gt;userdata('id_puskesmas'));
      }
      if(!$nama_file2 == ""){
          $this-&gt;app_model-&gt;insert_data('penyakit', $format_p2ptm2, $tanggal,$nama_file2,$jenis,$this-&gt;session-&gt;userdata('id_puskesmas'));
      }
      if(!$nama_file3 == ""){
          $this-&gt;app_model-&gt;insert_data('penyakit', $format_p2ptm3, $tanggal,$nama_file3,$jenis,$this-&gt;session-&gt;userdata('id_puskesmas'));
      }
      if(!$nama_file4 == ""){
          $this-&gt;app_model-&gt;insert_data('penyakit', $format_p2ptm4, $tanggal,$nama_file4,$jenis,$this-&gt;session-&gt;userdata('id_puskesmas'));
      }
      if(!$nama_file5 == ""){
          $this-&gt;app_model-&gt;insert_data('penyakit', $format_p2ptm5, $tanggal,$nama_file5,$jenis,$this-&gt;session-&gt;userdata('id_puskesmas'));
      }
  
      redirect('puskesmas/view_puskesmas');
  
  }
  </code></pre>
  
  <p>Here is my new code with errors:</p>
  
  <pre><code>public function proses_upload()
  {
  
      $gambar = array();
      $jumlah = count($_FILES['userfile']['name']);
  
      for ($i=0; $i &lt; $jumlah; $i++)
      { 
  
          $file_name = $_FILES['userfile']['name'][$i];
          $explode = explode('.',$file_name);
              // die(print_r($explode));
          $ekstensi = pathinfo($file_name, PATHINFO_EXTENSION);
          $bulan = date('M');
          $tahun = date('y') ;
          $kode  = $this-&gt;session-&gt;userdata('kode_puskesmas');
          $new_file_name = $explode[1].'_'.$kode.'_'.$bulan.$tahun.'.'.$ekstensi;
          $tmp_name = $_FILES['userfile']['tmp_name'][$i];        
          move_uploaded_file($tmp_name, "file/".$new_file_name);
          $gambar[$i] = $new_file_name;                 
      }
  
      $nama_file1 = $gambar[0];
      $format_p2ptm =1; 
      $tanggal = date("Y-m-d H:i:s");
      $jenis ='p2ptm';
  
      $nama_file2 = $gambar[1];
      $format_p2ptm2 =2; 
      $jenis ='p2ptm';
  
      $nama_file3 = $gambar[2];
      $format_p2ptm3 =3;
      $jenis ='p2ptm';
  
      $nama_file4 = $gambar[3];
      $format_p2ptm4 =4;
      $jenis ='p2ptm';
  
      $nama_file5 = $gambar[4];
      $format_p2ptm5 =5; 
      $jenis ='p2ptm';
  
      if (!$nama_file1 == "") {
          $this-&gt;app_model-&gt;insert_data('penyakit', $format_p2ptm, $tanggal,$nama_file1,$jenis, $this-&gt;session-&gt;userdata('id_puskesmas'));
      }
      if(!$nama_file2 == ""){
          $this-&gt;app_model-&gt;insert_data('penyakit', $format_p2ptm2, $tanggal,$nama_file2,$jenis,$this-&gt;session-&gt;userdata('id_puskesmas'));
      }
      if(!$nama_file3 == ""){
          $this-&gt;app_model-&gt;insert_data('penyakit', $format_p2ptm3, $tanggal,$nama_file3,$jenis,$this-&gt;session-&gt;userdata('id_puskesmas'));
      }
      if(!$nama_file4 == ""){
          $this-&gt;app_model-&gt;insert_data('penyakit', $format_p2ptm4, $tanggal,$nama_file4,$jenis,$this-&gt;session-&gt;userdata('id_puskesmas'));
      }
      if(!$nama_file5 == ""){
          $this-&gt;app_model-&gt;insert_data('penyakit', $format_p2ptm5, $tanggal,$nama_file5,$jenis,$this-&gt;session-&gt;userdata('id_puskesmas'));
      }
  
      redirect('puskesmas/view_puskesmas');
  }
  </code></pre>
  
  <p>Here is my view form:</p>
  
  <pre><code>&lt;?php echo form_open_multipart('puskesmas/proses_upload');?&gt;
  
  &lt;br&gt;&lt;br&gt;&lt;br&gt;
  &lt;p&gt;
      &lt;h4&gt;1. Form Lap PTM&lt;/h4&gt;
  &lt;/p&gt;
  &lt;p&gt;
      &lt;label&gt;FORMAT : &lt;/label&gt; 
      &lt;input type="text" name="format"  style="width:230px; height:25px; border:2;  " 
      placeholder="Form Lap PTM" readonly&gt;
  &lt;/p&gt;
  &lt;label &gt;Input file : &lt;/label&gt; 
  &lt;input type="file" name="userfile[]"&gt;
  &lt;br&gt;&lt;br&gt;&lt;br&gt;
  
  
  
  &lt;p&gt;
      &lt;h4&gt;2. Form Lap Posbindu&lt;/h4&gt;
  &lt;/p&gt;
  &lt;p&gt;
      &lt;label&gt;FORMAT : &lt;/label&gt; 
      &lt;input type="text" name="format2"  style="width:230px; height:25px; border:2;  "
      placeholder="Form Lap Posbindu " readonly =&gt;
  
  &lt;/p&gt;
  
  &lt;label&gt;Input file : &lt;/label&gt; 
  &lt;input type="file" name="userfile[]"&gt;
  
  &lt;br&gt;&lt;br&gt;&lt;br&gt;
  
  
  
  
  &lt;p&gt;
      &lt;h4&gt;3. Form Lap IVA&lt;/h4&gt;
  &lt;/p&gt;
  &lt;p&gt;
      &lt;label&gt;FORMAT : &lt;/label&gt; 
      &lt;input type="text" name="format3"  style="width:230px; height:25px; border:2;  "
      placeholder="Form Lap IVA " readonly&gt;
  
  &lt;/p&gt;
  
  &lt;label&gt;Input file : &lt;/label&gt; 
  &lt;input type="file" name="userfile[]"&gt;
  &lt;br&gt;&lt;br&gt;&lt;br&gt;
  
  
  
  
  &lt;p&gt;
      &lt;h4&gt;4. Form Lap Jiwa&lt;/h4&gt;
  &lt;/p&gt;
  &lt;p&gt;
      &lt;label&gt;FORMAT : &lt;/label&gt; 
      &lt;input type="text" name="format4"  style="width:230px; height:25px; border:2;  "
      placeholder="Form Lap Jiwa" readonly&gt;
  
  &lt;/p&gt;
  
  &lt;label&gt;Input file : &lt;/label&gt; 
  &lt;input type="file" name="userfile[]"&gt;
  &lt;br&gt;&lt;br&gt;&lt;br&gt;
  
  
  
  &lt;p&gt;
      &lt;h5&gt;5. Form Lap Indera dan Gimul&lt;/h5&gt;
  &lt;/p&gt;
  &lt;p&gt;
      &lt;label&gt;FORMAT : &lt;/label&gt; 
      &lt;input type="text" name="format5"  style="width:230px; height:25px; border:2;  "
      placeholder="Form Lap Indera_dan Gimul" readonly&gt;
  &lt;/p&gt;
  
  &lt;label&gt;Input file : &lt;/label&gt; 
  &lt;input type="file" name="userfile[]"&gt;
  &lt;br&gt;&lt;br&gt;&lt;br&gt;
  
  
  
  
  &lt;!-- &lt;button class="" type="submit"&gt;Upload&lt;/button&gt; --&gt;
  &lt;input class="btn btn-primary btn-lg" type="submit" value="Upload"&gt;
  &lt;?php echo form_close() ?&gt;
  </code></pre>
  
  <p>if I upload files one of the 5 inputs that for the column I fill in the input is true, but why do the remaining 4 other inputs also enter data? even though I only input 1 input</p>
  
  <p><a href="https://ibb.co/59RKJ4B" rel="nofollow noreferrer">its my phpmyadmin foto input</a></p>