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();
// 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();
Related PostsIf you liked How to Multiple File Upload with CodeIgniter; the posts below might interest you too:
|




May 1, 2012
18:21
Tnx alot