SOLVED
I have a file field named additional_photos[] on a web page, there can be n number of instances of this field of course with different ID but same name. In a normal PHP code I will do a foreach on $_FILES['additional_photos'] and will do rest easily. But how do I achieve the same with CodeIgniter? I tried doing this:
$additional_photosCount = count($_FILES['additional_photos']['name']); //Is there a better way to refer $_FILES like I can refere $_POST in CI?
for($i=0; $i< $additional_photosCount; $i++){
$uploadConfig['file_name'] = $this->properties['userId'].'-'.$_FILES['additional_photos']['name'][$i];
$this->CI->upload->initialize($uploadConfig);
if(!$this->CI->upload->do_upload('additional_photos['.$i.']')){;
echo $this->CI->upload->display_errors();
}
}
But this,
a) IMHO, isn't correct way
b) gives me error "You did not select a file to upload."
Update
This is a way out I could apply:
$additional_photosCount = count($_FILES['additional_photos']['name']);
for($i=0; $i< $additional_photosCount; $i++){
$uploadConfig['file_name'] = $this->properties['userId'].'-'.$_FILES['additional_photos']['name'][$i];
$this->CI->upload->initialize($uploadConfig);
$_FILES['additional_photos_'.$i] = array(
'tmp_name'=> $_FILES['additional_photos']['tmp_name'][$i],
'name'=> $_FILES['additional_photos']['name'][$i],
'type'=> $_FILES['additional_photos']['type'][$i],
'size'=> $_FILES['additional_photos']['size'][$i],
'error'=> $_FILES['additional_photos']['error'][$i],
);
if(!$this->CI->upload->do_upload('additional_photos_'.$i)){;
echo $this->CI->upload->display_errors();//TODO: instead of echoing push errors to a list
}
}