Codeigniter multiple file upload messes file extension

后端 未结 5 1454
梦如初夏
梦如初夏 2020-11-29 22:41

I am trying to get a multiple upload library working for my Codeigniter based website. I have it working almost but I have a slight problem if I upload more than one image,

5条回答
  •  粉色の甜心
    2020-11-29 23:14

    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; }
    
    }
    

提交回复
热议问题