使用http-header强制下载字符串

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 . "
";
    foreach($arr as $row) {
        $csv .=$row[0] . "  " .  $row[1] . "    ". $row[2] . "  " .$row[3] . "  
";
    }
    $filename = "emails_".date("Y-m-d_H-i",time());


    header ("Content-Type: application/octet-stream");
    header ("Content-disposition: attachment; filename=".$filename.".csv");
    print $csv;
}

The problem was not with the function.

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

Try Content-Disposition with a capital D.

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