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-disposition: attachment; filename="data.csv"');    
$data = array (
    'aaa,bbb,ccc,dddd',
    '123,456,789',
    '"aaa","bbb"');
$fp = fopen('php://output', 'w+');  
foreach($data as $line){
    $val = explode(",",$line);
    fputcsv($fp, $val);
}
fclose($fp);  
It gives me my source file code also in the csv file? How can I solve this?


$headervariable come from?