I'm beginning work on a project that requires that I take multiple arrays and put them in a csv file. However, although it is generating the file, it is generally completely empty(0 b file size). Occasionally, if I miss something, it will put the error message in the file, or a couple times it puts the array in the file as though I had done print_r($array).
currently, I have this:
<?php
// output headers
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=file.csv');
$list = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('123', '456', '789'),
array('"aaa"', '"bbb"')
);
$fp = fopen('file.csv', 'w');
// output data
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
?>
The arrays used will eventually be generated, but I'm new to generating files, so I wanted to do this first.
I've also tried multiple variations on this, with the same results. So far, the only thing I can think of is that I'm using XAMPP, and that there is some problem with the fputcsv function therein, but I haven't found anybody else with this problem. Is there an error in my code, or should I be looking for my problem elsewhere?