Codeigniter Download Helper Codeigniter download helper enables you to download data from server to your system. It is very easy to use the download helper. Here in this tutorial we are going to explain how you can load this helper and use it’s functions.
Codeigniter Download Helper | Load | Syntax Example
Let us first see how to load download helper in codeigniter and then use its function-
Load Download Helper
To load Download Helper in Codeingniter Example:
$this->load->helper('download'); |
Functions
Following functions are available in download helper.
force_download
Syntax of force_download function is-
force_download Function Syntax:
force_download($filename , $data, $set_mime) |
Parameters-
Following parameters are accepted by force_download function-
- $filename(string) – Name of file.
- $data(mixed) Content of file.-
- $set_mime(bool) – Whether to try to send the actual MIME type
Return Type-
Return Type of this function is void.
Example 1
Here is simple example to download the image.
Download File in Codeigniter Example:
$this->load->helper('download'); force_download('/img/myimage.jpg', NULL); |
Example 2
Download File in Codeigniter Example:
$this->load->helper('download'); $data = 'This is dummy content'; $name = 'myFile.txt'; force_download($name, $data); |