File Download in Code Igniter

In CodeIgniter, we can easily make files for download. There is a helper class called download, which we are using for downloading files from server. We just need a controller function and a view file.

Copy and modify the below code in controller.


public function download_file ($file_path = "")
$this->load->helper('download'); //load helper class

//$file_path = $this->input->post("file_path",TRUE);

$data['download_path'] = $file_path;

$this->load->view("view file",$data);
redirect("same url", "refresh");



In view file:


if( !empty($download_path))
$data = file_get_contents(base_url() ."/path/".$download_path); // Read the file's contents
$name = $download_path;
force_download($name, $data);


Now you can download files from your server easily. Enjoy coding with Code Igniter.


One Response
  1. Anonyms August 26, 2014 / Reply

Leave a Reply

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