I have to create and write into a csv file. Now I tried with the following code:
header(\'Content-type: application/octet-stream\');
header(\'Content-dispo
Try this:
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$data = array (
'aaa,bbb,ccc,ffffdd',
'123,456,789',
'"aaa","bbb"');
$fp = fopen('php://output','w');
foreach ($data as $line) {
fputcsv($fp, array_map('utf8_decode',array_values($line)), ',', '"');
}
fclose($fp);
Change the first header to header('Content-type: text/csv');
header() needs to come after the array and fopen
try this:
$data = array (
'aaa,bbb,ccc,ffffdd',
'123,456,789',
'"aaa","bbb"');
$fp = fopen('php://output', 'w+');
header('Content-type: application/octet-stream');
header('Content-disposition: attachment; filename="data.csv"');
foreach($data as $line){
$val = explode(",",$line);
fputcsv($fp, $val);
}
fclose($fp);
Wrap it in <?php
and ?>
tags.