Codeigniter Multiple Files Upload with Example





hii guys,

In this tutorial,I will learn how to upload multiple images with codeigniter 3 Framework. when you upload multi images codeigniter then this type can simply use the multiple file upload in project.

you will make the form and some designing with bootstrap and you will also use multiple attributes for the upload multiple images.

Step 1: Create Upload Directory

you will create assets/uploads/ directory on own project directory.

Step 2: Create The Controller

you will create the Multipleimage.php controller in the controller directory.

you will load the model and helper URL. when the user submits the form and uploads images that time we will check the condition and count how many images upload. you will be uploading images using the for loop. you rename all images using the PATHINFO_EXTENSION and pathinfo.


defined('BASEPATH') OR exit('No direct script access allowed');

class Multipleimage extends CI_Controller {

public function __construct() {





public function index(){

if ($this->input->post('submit') && $_FILES['images']['name'] != '') {

$data = array();

$count_images = count($_FILES['images']['name']);



$ext = pathinfo($_FILES['images']['name'][$i], PATHINFO_EXTENSION);

$name = 'image' . rand(100000, 999999) . date("Y-m-d") . '.' . $ext;

$_FILES['file']['name'] = $name;

$_FILES['file']['type'] = $_FILES['images']['type'][$i];

$_FILES['file']['tmp_name'] = $_FILES['images']['tmp_name'][$i];

$_FILES['file']['error'] = $_FILES['images']['error'][$i];

$_FILES['file']['size'] = $_FILES['images']['size'][$i];

$config['upload_path'] = './assets/uploads/';

$config['allowed_types'] = 'jpg|jpeg|png|gif';

$config['max_size'] = '10000';

$config['file_name'] = $_FILES['images']['name'][$i];



$uploadData = $this->upload->data();

$arrData["image_name"] =$name;










Step 3: Create The Model

you will create the Image_model.php model in the model directory.


defined('BASEPATH') OR exit('No direct script access allowed');

Class Image_model extends CI_Model


function save_image($arrData)


if ($this->db->insert('file_upload_image',$arrData)) {

return true;

} else {

return flase;





Step 4: Create The View

you will create the image.php file in the views directory.

<!DOCTYPE html>

<html lang="en">


<title>Codeigniter Multiple Files Upload Example/</title>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="">

<script src=""></script>

<script src=""></script>



<div class="container">

<div class="row">

<div class="col-sm-12">

<section class="panel">

<header class="panel-heading col-sm-12">

<h1 class="col-sm-6">Codeigniter Multiple Files Upload Example</h1>


<div class="container">

<div class="panel-body">

<div class="form">


$attributes = array('name' => 'frmimage', 'id' => 'frmimage', 'class' => 'imageform form-horizontal adminex-form');

echo form_open_multipart('',$attributes);


<div class="form-group col-sm-12 ">

<div class="col-lg-8 ">

<input type="file" name="images[]" multiple class="form-control">



<div class="form-group col-sm-12">

<div class="col-lg-1 col-xs-offset-2">


$datasubmit = array(

'name' => 'submit',

'id' => 'submit',

'class' => 'btn btn-success',

'value' => 'File Upload'


echo form_submit($datasubmit);





<?php echo form_close(); ?>









It will help you....

Recommended Posts