Welcome Guest, Not a member yet? Register   Sign In
how to upload multiple file in a single form in codeigniter

can anybody help me out to upload multiple file from a single form. if possible please give some example. below is my code in model for upload function it works fine for single upload, but doesn't work for multiple uploads from a single form.

function upload(){
            'upload_path'=>  $this->gallery_path,

Thanks in Advance.

It's not possible to do that natively. People seem to be using this: https://github.com/stvnthomas/CodeIgniter-Multi-Upload

Had the same problem as you did solved it on this thread.

Its long but the answers are here.

Any questions just post on this thread and Fuzzy or myself will help you Big Grin

[eluser]Bigil Michael[/eluser]
use for loop to upload more than one image at a time


function demo(){
       //upload thumbnail      $c
     $config['upload_path'] = 'Your folder path';
     $config['allowed_types'] = 'gif|jpg|jpeg|png';
     $config['file_name'] = '0'.$i;
     $config['max_size'] = '150';    
     if ( ! $this->upload->do_upload('photo_'.$i))
      $data['alert'] = $this->upload->display_errors();
      $upload_data = $this->upload->data();
      $filename = $upload_data['file_name'];
      $width = $upload_data['image_width'];
      $height = $upload_data['image_height'];
      $config1 = array();
      $config1['source_image'] = 'your folder/'.$filename;
       //resize image
       $sizes = array('width' => $width, 'height' => $height, 'new_width' => 762, 'new_height' => 325);
       $newsize = array();
       $newsize = $this->image_lib->size_calculator($sizes);
       $config1['maintain_ratio'] = FALSE;
       $config1['width'] = $newsize['new_width'];
       $config1['height'] = $newsize['new_height'];
                                                // creating thumb
      $config1['maintain_ratio'] = FALSE;
      $config1['width'] = 762;
      $config1['height'] = 325;
      $config1['create_thumb'] = TRUE;
      $config1['thumb_marker'] = 'thumb_';
      $this->Your model->save_image('photo_'.$i,$filename);
      $data['alert'] = 'image uploaded';
    $data['image'] = $this->Yoourmodel->get_homepage(); // select photos
    $this->load->view('your view', $data);
    $this->load->view('your view', $data);


function save_image($field,$filename=''){
   $data[$field] = $filename;
  $this->db->where('id',1);// item  id

I don't think that's what the OP means. I suspect he has an upload field with the multiple="" attribute, meaning you can select any number of files from the file picker window, and they are uploaded in an array.

Bigil you need to have a look at this extended library :


you are doing way to much work to upload multiple files.

Literally with this library all you have to do is :



and your done.


[eluser]Bigil Michael[/eluser]
Good one. Thanks RaGe10940.

Heres a more in depth look at some of my code to further assist any one else looking into doing multiple uploads with a single form field.

as Fuzzy said with one form field just use


then do :
$this->load->library('upload'); // Load Library

   $this->upload->initialize(array( // takes an array of initialization options
       "upload_path" => "/usr/local/var/www/Test/ci/uploads/",
       "overwrite" => TRUE,
       "encrypt_name" => TRUE,
       "remove_spaces" => TRUE,
       "allowed_types" => "txt|pdf",
       "max_size" => 300,
       "xss_clean" => FALSE
   )); // These are just my options. Also keep in mind with PDF's YOU MUST TURN OFF xss_clean

   if ($this->upload->do_multi_upload("files")) { // use same as you did in the input field
       $return = $this->upload->get_multi_upload_data(); // then just use function from the extended library

in my case I had to do this for a email system which Fuzzy helped me on so then do this :

foreach ($return as $file) { // loop over the upload data
    $this->email->attach($file['full_path']); // attach the full path as an email attachments :D


[eluser]Tiến Thành[/eluser]
[quote author="TheFuzzy0ne" date="1365534088"]It's not possible to do that natively. People seem to be using this: https://github.com/stvnthomas/CodeIgniter-Multi-Upload[/quote]
Thank you so much

Example http://www.webtuts.in/codeigniter-multip...es-upload/

Theme © iAndrew 2016 - Forum software by © MyBB