Tag Archives: codeigniter download file from server
Codeigniter download file example
Codeigniter download file example : To download any file in codiegniter we need download helper so first of all load download helper then use it’s download method. Here in this tutorial, we are going to explain how you can download file in CI using download helper with simple example.
Syntax : Codeigniter download file example
Load Helper
First of all you need to load helper simply as below-
$this->load->helper('download');
After loading helper you can access it’s function to download file.
force_download('filename', 'data');
filename : The name of the downloadble file.
data : Content of the file.
Example:
Here is an example to download file from the server.
$data = file_get_contents("/path/my-image.jpg"); force_download('my-today-day.jpg', 'data');
File will be downloaded in with name my-today-day.jpg.