Flush the output buffer with the ob_clean () function just before you get your data.
Your code should now look like this.
$this->load->helper('download'); $path = base_url('reference/filename.xlsx'); ob_clean(); $data = file_get_contents($path); // Read the file contents $name = 'filename.xlsx'; force_download($name, $data);
source share