How to Multiple File Upload with CodeIgniter

Upload multiple images in one same form is not that simple.

In your Controller function you have to initialize the upload for each file.

And the same if you want to Resize Multiple Images, you will have to initialize the resize for each file.


// File 1
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_width'] = '100';
$config['max_height'] = '100';
$this->upload->initialize($config); // Important

// Image 2
$config['upload_path'] = './avatars/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_width'] = '150';
$config['max_height'] = '150';
$this->upload->initialize($config); // Important

// Resize the Image 2

$file_data = $this->upload->data(); // get the file upload data

$this->load->library('image_lib', $resize_me); // load the library

$filenew = rename("./avatars/" . $file_data['file_name'], "./avatars/newfile".$file_data['file_ext']);

$resize_me['image_library'] = 'gd2';
$resize_me['source_image'] = "./avatars/newfile".$file_data['file_ext'];
$resize_me['create_thumb'] = FALSE;
$resize_me['maintain_ratio'] = FALSE;
$resize_me['width'] = 10;
$resize_me['height'] = 10;


About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.
One comment

Leave a Reply

Add <code> Some Code </code> by using this tags.