CodeIgniter Forums
force_download on a link - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: force_download on a link (/showthread.php?tid=44771)



force_download on a link - El Forum - 08-26-2011

[eluser]Wonder Woman[/eluser]
Hi there,

I want to force a file to download when a user clicks on a link or a button...I have tried this with no such luck.

Can you help me? I currently have the following code...

view:
Code:
echo anchor(base_url().'admin/data/download/'.$record['file_name'], 'Download');

controller:

Code:
function download() {
   $this->load->helper('download');        
   $data = file_get_contents('./uploads/data/'.$this->uri->segment(4));
   $name = $this->uri->segment(4);
   force_download($name, $data);
   $this->load->view('admin/data/index');
}

Many thanks!