Welcome Guest, Not a member yet? Register   Sign In
CI3: Multiple File Upload

Hi Guys,

Basing from http://www.codeigniter.com/userguide3/li...ading.html 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.

(This post was last modified: 12-09-2014, 09:12 AM by Dracula.)

You must have multiple in your upload input like this...
<input type="file" name="userfile" size="20" multiple>
Romanian CodeIgniter Team :: Translations :: Comunity :: Developers

If you have the time, please do look at my latest tutorial about uploading multiple files: http://avenir.ro/codeigniter-tutorials/u...deigniter/

Theme © iAndrew 2016 - Forum software by © MyBB