Reputation: 6943
I'm having a problem with my function. The purpose of my function is to force a string to be downloaded. What it really happens is that the string is outputted to the screen and not downloaded.
This is my function:
function arrayToCSV($vectorDados, $cabecalho)
{
$arr = array();
$arr=$vectorDados;
$csv = $cabecalho . "\n";
foreach($arr as $row) {
$csv .=$row[0] . " " . $row[1] . " ". $row[2] . " " .$row[3] . " \n";
}
$filename = "emails_".date("Y-m-d_H-i",time());
header ("Content-Type: application/octet-stream");
header ("Content-disposition: attachment; filename=".$filename.".csv");
print $csv;
}
Upvotes: 2
Views: 2918
Reputation: 6943
The problem was not with the function.
By adding ob_start() to the main code, now I'm able to download my string.
Upvotes: 3
Reputation: 9931
Try Content-Disposition with a capital D.
(and maybe text/csv for the Content-Type)
Upvotes: 1