"Cannot modify header" when writing download file invoked from _POST
-
I am writing a plugin and have an Archive page which allows the administrator to download and upload files, so that the Custom Post Types can be saved and reconstructed.
There are several different types of files and options for downloading them. Those options that are invoked by a static link such as the following work fine:
<a href="admin.php?action=gig_export_all_attributes" title="Export all Attributes as JSON archive file" rel="permalink">Export all Attributes as JSON file</a>
However, in the case of a couple of options, the user needs to make a selection from a drop-down list and the selection is passed back from an HTML form via a $_POST variable. Only in the case of those two options do I get problems: all of the lines in which header data is written for the purposes of the output file cause the error “PHP Warning: Cannot modify header information – headers already sent by (output started at…”
The code that creates the files is exactly the same:
header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private', false); header('Content-Type: text/plain; charset=utf-8'); header('Content-Disposition: attachment; filename="'.$filename.'";'); header("Content-Transfer-Encoding: binary"); // This opens up the output buffer as a "file" $fp = fopen('php://output', 'w'); // Hack to write as UTF-8 format fwrite($fp, pack("CCC",0xef,0xbb,0xbf));
Please help!
- The topic ‘"Cannot modify header" when writing download file invoked from _POST’ is closed to new replies.