views:

100

answers:

2

Hi, 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;
}
+1  A: 

Try Content-Disposition with a capital D.

(and maybe text/csv for the Content-Type)

skrebbel
Done that, but the string still is outputted to the screen. Thanks anyway
Armadillo
+1  A: 

The problem was not with the function.

By adding ob_start() to the main code, now I'm able to download my string.

Armadillo