CodeIgniter Forums

Full Version: CI3: Multiple File Upload
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Guys,

Basing from I'm trying to implement method ('process_upload'), that would upload multiple files. the idea is basically from the tutorial, only i added some loop just in case of multiple input.
PHP Code:
public function process_upload$input_field_name$config = array() ) {
 for ($key 0$key count($_FILES[$input_field_name]['name']); $key++) {
   $_FILES[$input_field_name]['name'    $_FILES[$input_field_name]['name'][$key];
   $_FILES[$input_field_name]['type'    $_FILES[$input_field_name]['type'][$key];
   $_FILES[$input_field_name]['tmp_name'] = $_FILES[$input_field_name]['tmp_name'][$key];
   $_FILES[$input_field_name]['error'   $_FILES[$input_field_name]['error'][$key];
   $_FILES[$input_field_name]['size'    $_FILES[$input_field_name]['size'][$key];


   if ( !$this->upload->do_upload($input_field_name) ) {
     return array('upload_error' => $this->upload->display_errors());
   } else {
     return array('upload_data' => $this->upload->data());

Then call the method ('process_upload') in other method ('set_upload') like:
PHP Code:
public function set_upload() {
 // Config your upload settings
 $config['upload_path'     './public/images/';
 $config['allowed_types'   'gif|jpg|png';
 $config['max_size'        '100';
 $config['max_width'       '1024';
 $config['max_height'      '768';

 $field 'myfile'// Input File field
 $data $this->process_upload($field$config);

Now, if i try to upload 3 files, only 1 file is uploaded  to its upload path directory. Cany anyone please help, how can i resolved this issue.

Thanks, in advanced.
You must have multiple in your upload input like this...
<input type="file" name="userfile" size="20" multiple>
If you have the time, please do look at my latest tutorial about uploading multiple files: