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.

$this->load->library('upload'); // 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 $this->upload->do_upload("my_field_name_1"); // 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 $this->upload->do_upload("my_field_name_2"); // 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; $this->image_lib->resize();
Code language: PHP (php)

About Ricard Torres

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

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast

2 comments

Leave a Reply

Add <code> Some Code </code> if you need to.

*
*