How to Multiple File Upload with CodeIgniter

31 January 2011 by Rick ~ 1 Comment 4138 views

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();

Subscribe by E-mail:

« »

One Comment

  1. Tnx alot

     

Add a Comment

Use [code] example piece of code [/code] to insert code into your comment.