Welcome Guest, Not a member yet? Register   Sign In
Multiple file uploads and get the name of the uploaded file
#1

[eluser]Unknown[/eluser]
Code:
$config['upload_path'] = './property_image/';
         $config['allowed_types'] = 'gif|jpg|jpeg|png';
         $config['max_size']         = '2240';
   $this->load->library('upload', $config);
  
   for($i = 0;$i<=14;$i++){
    $name = 'media_image_0'.$i;
    if($i>9){
     $name = 'media_image_'.$i;
    } // end of if($i>9
    if(isset($_FILES[$name])){
    
     $this->upload->do_upload($name);
     $idata = $this->upload->data();
     dump($idata['file_name']);

    }else{
     // do nothing
    }// end of if(!empty
   } // end of for loop

This code above uploads multiple images but the problem is,
if I select only one image, (let's say, in the first field) all other fields get the same name. How can I stop it?
I know the problem too, it's $idata = $this->upload->data(); ... $idata needs to be different for every field.
But I'm not being able to make it work. Please help me. I need to get the name too.
#2

[eluser]Pert[/eluser]
It's possible $_FILES['media_image_02'] is still set, just empty. If you upload only one file, what does this code return?

Code:
echo '<pre>'.print_R($_FILES, true).'</pre>';




Theme © iAndrew 2016 - Forum software by © MyBB