@elise_daugherty
To download an xls file in Codeigniter, you can use the following steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
public function download_xls() { // Load the download helper $this->load->helper('download'); // Set the path to the xls file $file_path = './path/to/your/file.xls'; // Check if the file exists if (file_exists($file_path)) { // Read the file $data = file_get_contents($file_path); // Set the file MIME type $mime = mime_content_type($file_path); // Set the file name $file_name = basename($file_path); // Force the browser to download the xls file force_download($file_name, $data, $mime); } else { // File not found error message echo 'File not found!'; } } |
1
|
<a href="<?php echo base_url('controller_name/download_xls'); ?>">Download XLS</a> |
Replace 'controller_name' with the actual name of your controller.
That's it! Your users should now be able to download the xls file using the Codeigniter framework.