[eluser]Dinesh Shah[/eluser]
I hit this CI bug. The funny part was that it was working OK in my development server but was broken on my production server.
The issue is CI output class sends a spurious new line ("\n") before sending any custom headers.
Non-working code using CI's output class
Code:
$this->output->set_header("HTTP/1.0 200 OK");
$this->output->set_header("HTTP/1.1 200 OK");
$this->output->set_header('Expires: 0');
$this->output->set_header('Cache-control: private');
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache");
$this->output->set_header('Content-Description: File Transfer');
$this->output->set_header("Content-type: text/csv");
// $this->output->set_header("Content-type: application/csv");
$this->output->set_header("Content-Disposition: attachment; filename=\"Client_Net_Balance-" . date('Y-m-d') . ".csv\"");
echo $csv_file;
Working code using PHP's native header function. This works without any problem on development and production servers.
Code:
header("HTTP/1.0 200 OK");
header("HTTP/1.1 200 OK");
header('Expires: 0');
header('Cache-control: private');
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0");
header("Pragma: no-cache");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
// header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=\"Client_Net_Balance-" . date('Y-m-d') . ".csv\"");
echo $csv_file;