HOW TO UPLOAD MULTIPLE FILES WITH CODEIGNITER ?

This post is regarding to the Uploading multiple files in CodeIgniter. CodeIgniter has own class for uplod the image so using image upload class we can upload multiple images.

File Uploding Class: https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

For Uploading files You need to upload library :

$this->load->library('upload');

Using do_uplod() Method you can uploads file in CodeIgniter.

$this->upload->do_upload()

VIEW SECTION: prfile_view.php

Upload Multiple File in Codignitor

CONTROLLER SECTION: profile.php

class Profile extends CI_Controller {
 
        function __construct()
        {
                parent::__construct();
                $this->load->model('your_model_here');
                $this->load->helper(array('form', 'url'));
        }
        function index()
        {
                $this->load->view('profile_view');
        }


        function multiple_image_upload()
        {

            $this->load->library('upload');
            $files = $_FILES;
            $count = count($_FILES['profileimage']['name']);
            for($i=0; $i<$count; $i++)
            {
                $_FILES['profileimage']['name']= $files['profileimage']['name'][$i];
                $_FILES['profileimage']['type']= $files['profileimage']['type'][$i];
                $_FILES['profileimage']['tmp_name']= $files['profileimage']['tmp_name'][$i];
                $_FILES['profileimage']['error']= $files['profileimage']['error'][$i];
                $_FILES['profileimage']['size']= $files['profileimage']['size'][$i];    
                $this->upload->initialize($this->set_upload_options());
                if($this->upload->do_upload() == False)
                {
                    //error coming here
                    $this->load->view('profile_view');
                }
                else
                {
                  // Insert Code here
                }

            }

        }
        private function set_upload_options()
        {   

            $config = array();
            $config['upload_path'] = './profile_images/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['overwrite']     = FALSE;
            return $config;
        }

}

About The Massive Technolab

Avatar
Who We Are

Massive Technolab is a Leading IT services Company in India that expertise in web Development, Web Design and SEO at affordable rates.

Leave a Comment

comments powered by Disqus