CodeIgniter has a nice helper class to download files. Its a nice way to download from server without any hassle just writing one single controller function.

public function download ($file_path = "")
	{
			$this->load->helper('download'); //load helper
			
			//$file_path = $this->input->post("file_path",TRUE);
			
			$layout="no_theme"; //if you have layout
			
			$data['download_path'] = $file_path;		
						
			$this->load->view("view file",$data);
			redirect("same url", "refresh");						
					
	}

In view section, just call the download function thats it.

	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);

	}

Its the most simple process to download using CodeIgniter

Advertisements