1

Can someone help me out to upload multiple file from a single form. If possible please give some example. I have go through several places over internet but didn't find any solution. 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(){
     $config[$a]=array(
        'allowed_types'=>'xlsx',
        'upload_path'=>  $this->gallery_path,
        'overwrite'=>true,
        'max_size'=>2000,
    );
     $this->load->library('upload',$config);
    $this->upload->do_upload();

}

Thanks in advance.

Trinimon
  • 13,839
  • 9
  • 44
  • 60
leon24
  • 5
  • 3

1 Answers1

0

Try this:

function do_upload()
{
    foreach ($_FILES as $index => $value)
    {
        if ($value['name'] != '')
        {
            $this->load->library('upload');
            $this->upload->initialize($this->set_upload_options());

            //upload the image
            if ( ! $this->upload->do_upload($index))
            {
                $error['upload_error'] = $this->upload->display_errors("<span class='error'>", "</span>");

                //load the view and the layout
                $this->load->view('pages/uploadform', $error);

                return FALSE;
            }
            else
            {

                 $data[$key] = array('upload_data' => $this->upload->data());

                 $this->load->view('pages/uploadsuccess', $data[$key]);


            }
        }
    }

}

//here put your rules
private function set_upload_options()
{   
    //upload an image options
    $config = array();

    $config['upload_path']   = FCPATH.'public/uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['encrypt_name']  = TRUE;
    $config['max_width']     = '2000';
    $config['max_height']    = '1500';
    $config['max_size']      = '2048';

    return $config;
}
Sangar82
  • 5,070
  • 1
  • 35
  • 52