w3programmers - Making File Upload System Using CodeIgniter Framework

Making File Upload System Using CodeIgniter Framework

In This Tutorial I will discuss How to Make File Upload System Using PHP CodeIgniter Framework.

At Essentially in CodeIgniter to do upload file we have given her class to help us developers, and this time we will discuss the class.

Let’s discussed step by step below:

  1. Create upload_form.php file and place it in the application / views and type the following script:


<title>CodeIgniter Upload Form </title>



<?php echo $error;?>

<?php echo form_open_multipart('fileupload/do_upload');?>

<input type="file" name="userfile" size="20" />

<br /><br />

<input type="submit" value="upload" />




2.       Then create upload_success.php file and place it in application / views and contents of the script as follows:



<title>File Upload Success </title>



<h3>Your file was uploaded successfully </h3>


<?php foreach ($upload_data as $item => $value):?>

<li><?php echo $item;?>: <?php echo $value;?></li>

<?php endforeach; ?>



<?php echo anchor('upload', 'Other files uploaded!'); ?>




3.       If you’ve made the files for views, now we create a file for the controllers. Create fileupload.php and place in application / controllers / with the following script:


class Upload extends CI_Controller {

function __construct()



$this->load->helper(array('form', 'url'));


function index()


$this->load->view('upload_form', array('error' => ' ' ));


function do_upload()


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

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

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

$config['max_width']  = '1024';

$config['max_height']  = '768';

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


if ( ! $this->upload->do_upload())


$error = array('error' => $this->upload->display_errors());

$this->load->view('upload_form', $error);




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

$this->load->view('upload_success', $data);





Here I Give a little explanation upload.php:

$this->load->helper(array(‘form’, ‘url’)); Meaning that it can be removed if you have defined in config / autoload.
$config[‘upload_path’] = ‘./uploads/’; Location or folder you want to be created first file uploads folder on your CI web folder. (Create a new folder file storage) If you want to eliminate those headaches that come with storing your data, you can visit the website salesforce.com to learn more about cloud computing.
$config[‘allowed_types’] = ‘gif|jpg|png’; file types are allowed to be uploaded, it can be tailored to the needs.
$config[‘max_size’] = ‘100’;$config[‘max_width’] = ‘1024’;$config[‘max_height’] = ‘768’; file size and length to the width of the image, it can also be customized according to the needs.

If all the above stages have been completed correctly you created, now you just try to go to the link http://localhost/Your_CodeIgniter _Folder/ index.php/fileupload/

Now see the Final Result screenshots below:

File Upload Form

Figure 1: File Upload Form

CodeIgniter File Upload Success

Figure 2: File Upload Success Page


5 comments to “Making File Upload System Using CodeIgniter Framework”

Leave a Reply

Your email address will not be published. Required fields are marked *