Welcome Guest, Not a member yet? Register   Sign In
force_download outputs the file instead of sending the file for download
#1
Wink 

Hi, first post here Smile

Been learning CI for a few days now and I find it very nice Smile

Here is a problem I'm struggling with. I have an Excel file located at $file_name. I want to send it for download to the browser. I'm using the following :

PHP Code:
// Echo done
echo date('H:i:s') . " Done writing file.\r\n";

$this->load->library('zip');
$this->zip->add_data('excel_results.xls'file_get_contents($file_name));
$this->zip->archive('my_backup.zip');
$this->zip->download('my_backup.zip'); 

When I run this script, the file is not sent to the browser for download, but instead, it is output on the page:
[Image: skitch.png?resizeSmall&width=832]

... and I just found the problem Smile. But since it's my first post in here, I'm going to publish it anyway as it might help someone else Smile

So the problem is that I was echoing some code prior. This screwed the headers. I removed the echo, and now it's working perfectly.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB