CodeIgniter Laravel PHP Example Javascript jQuery MORE Videos New
Need a Website Or Web Application Contact : +91 9437911966 (Whatsapp) Note: Paid Service

How to upload file in CodeIgniter framework

In this example we are going to show you how to how to upload file in CodeIgniter framework.

Here we using 3 files for upload file in CodeIgniter:

  • Upload.php Path: codeIgniter\application\controllers\Upload.php
  • upload_form Path: codeIgniter\application\views\upload_form.php

Create a folder uploads under your project folder.

Upload.php (Controller)

class Upload extends CI_Controller {
      public function __construct() { 
         $this->load->helper(array('form', 'url')); 
      public function index() { 
         $this->load->view('upload_form', array('error' => ' ' )); 
    public function do_upload() { 
         $config['upload_path']   = './uploads/'; 
         $config['allowed_types'] = 'gif|jpg|png'; 
         $config['max_size']      = 1024; 
         $config['max_width']     = 1024; 
         $config['max_height']    = 1200;  
         $this->load->library('upload', $config);
         if ( ! $this->upload->do_upload('userfile')) {
            $error = array('error' => $this->upload->display_errors()); 
            $this->load->view('upload_form', $error); 
         else { 
            $data = array('upload_data' => $this->upload->data());
echo "File uploaded Successfully!"; } } } ?>

upload_form.php (View)

<!DOCTYPE html>
      <title>Upload Form</title> 
      <h3>Your file was successfully uploaded!</h3>  
         <?php foreach ($upload_data as $item => $value):?> 
         <li><?php echo $item;?>: <?php echo $value;?></li> 
         <?php endforeach; ?>
      <p><?php echo anchor('upload', 'Upload Another File!'); ?></p>  

Run the program on your browser with URL:


Here codeIgniter is my folder name. Put your folder name instead of codeIgniter.Rest of things are same.