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.

2
  • What is $a in $config[$a]? Commented Apr 9, 2013 at 21:24
  • sorry, my bad. ignore $config[$a], it will be $config Commented Apr 10, 2013 at 6:49

1 Answer 1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.