Codeigniter multiple file upload messes file extension

Faced the exact similar stuff 2 days ago but did it the old fashioned way hope it helps.
try this ..

function tester(){

 $this->load->library('upload');  // NOTE: always load the library outside the loop
 $this->total_count_of_files = count($_FILES['filename']['name'])
 /*Because here we are adding the "$_FILES['userfile']['name']" which increases the count, and for next loop it raises an exception, And also If we have different types of fileuploads */
 for($i=0; $i<$this->total_count_of_files; $i++)
 {

   $_FILES['userfile']['name']    = $_FILES['filename']['name'][$i];
   $_FILES['userfile']['type']    = $_FILES['filename']['type'][$i];
   $_FILES['userfile']['tmp_name'] = $_FILES['filename']['tmp_name'][$i];
   $_FILES['userfile']['error']       = $_FILES['filename']['error'][$i];
   $_FILES['userfile']['size']    = $_FILES['filename']['size'][$i];

   $config['file_name']     = 'test_'.$i;
   $config['upload_path']   = './public/uploads/';
   $config['allowed_types'] = 'jpg|jpeg|gif|png';
   $config['max_size']      = '0';
   $config['overwrite']     = FALSE;

  $this->upload->initialize($config);

  if($this->upload->do_upload())
  {
    $error += 0;
  }else{
    $error += 1;
  }
 }

 if($error > 0){ return FALSE; }else{ return TRUE; }

}

Leave a Comment