this question has answer here:
- how fix “headers sent” error in php 11 answers
i read whole bunch of articles in , internet , tried of them still unable create csv download functionality in php.
following code:
$csvdata = @$_post['csv_data']; if(trim($csvdata)) { header("cache-control: must-revalidate, post-check=0, pre-check=0"); header('content-description: file transfer'); header("content-type: text/csv"); header("content-disposition: attachment; filename=data.csv"); header("expires: 0"); header("pragma: public"); echo $csvdata; exit; }
instead of showing file save dialog, keeps printing csv data browser :( doing wrong here? appreciated..
additional edit: posting data script, takes data , tries download. script include inside file, problem? enabled error_reporting , found getting header modified error...
in http, headers sent before text output.
for reason, php close response header if output text.
make sure hold text output before header modification, example using ob-cache.
Comments
Post a Comment