Welcome Guest, Not a member yet? Register   Sign In
Header Response 200 and Content Type text/plain via Controller
#21

[eluser]shiftpoint[/eluser]
I actually found a work around. In the very first line of your controller add this:

<?php header("Content-Type: text/plain charset=UTF-8\r\n");

then you can use all of the CI built in stuff. That worked for me.
#22

[eluser]Unknown[/eluser]
Quote:I actually found a work around. In the very first line of your controller add this:

<?php header(“Content-Type: text/plain charset=UTF-8\r\n”);

then you can use all of the CI built in stuff. That worked for me.

Looks like you need a ; after text/plain. I think if this isn't there, it doesn't replace what's already been sent as a header, and the output class will also send a header.

Correct:

Quote:<?php header(“Content-Type: text/plain; charset=UTF-8\r\n”); ?>
#23

[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;
#24

[eluser]Unknown[/eluser]
I know the post is old, but I had a similar problem when trying to minify css files into one, and I needed to add expires and content-type header. set_output worked like a charm! (CI 2.1)




Theme © iAndrew 2016 - Forum software by © MyBB