• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random problem with set_header()

#1
I am having a random issue with Content-Disposition header not being sent from my controller, depending on the content.  Here is my controller function:


PHP Code:
public function download() {
        $this->output->set_content_type('text/csv');
        $this->output->set_header('Content-Disposition: attachment; filename="test.csv"');
        //header('Content-Disposition: attachment; filename="test.csv"');
        readfile('/tmp/test.csv');




If I un-comment the header() call, then it always works, but otherwise sometimes it works and sometimes not, seems to depend either on the content of /tmp/test.csv or else it is just plain random -- I have not been able to nail down any specific lines of content that consistently reproduce the issue.

It seems pretty simple but maybe I'm doing something wrong?

(This is CI 3.1.10, using PHP 7.3.11, with Apache 2.4 and modsecurity2)
Reply

#2
I would use the built in force_download in Codeigniter for this: https://codeigniter.com/user_guide/helpe...elper.html
Reply

#3
That works - and (bonus) I looked at the code for force_download() and it outputs in 1MB chunks so as to not overrun memory, which I was concerned about.

So thanks!

(But it would be nice to know what the heck is wrong with my example)
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.