Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用http头强制下载字符串_Php_String_Http Headers - Fatal编程技术网

Php 使用http头强制下载字符串

Php 使用http头强制下载字符串,php,string,http-headers,Php,String,Http Headers,我的功能有问题。 我的函数的目的是强制下载字符串。实际情况是字符串被输出到屏幕而不是下载 这是我的职责: function arrayToCSV($vectorDados, $cabecalho) { $arr = array(); $arr=$vectorDados; $csv = $cabecalho . "\n"; foreach($arr as $row) { $csv .=$row[0] . " " . $row[1] . "

我的功能有问题。 我的函数的目的是强制下载字符串。实际情况是字符串被输出到屏幕而不是下载

这是我的职责:

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;
}

尝试使用大写字母D进行内容处理


(对于内容类型可能是text/csv)

问题不在于函数


通过添加到主代码,现在我可以下载我的字符串。

完成了,但字符串仍然输出到屏幕上。无论如何谢谢你