Php 如何选择导出格式

Php 如何选择导出格式,php,excel,export,txt,Php,Excel,Export,Txt,我有这段代码,它将数据从sql数据库导出到xls文件中 header("Content-Disposition: attachment; filename=\"test.xls\""); header("Content-Type: application/vnd.ms-excel;"); header("Pragma: no-cache"); header("Expires: 0"); $out

我有这段代码,它将数据从sql数据库导出到xls文件中

header("Content-Disposition: attachment; filename=\"test.xls\"");
header("Content-Type: application/vnd.ms-excel;");
header("Pragma: no-cache");
header("Expires: 0");
$out = fopen("php://output", 'w');
$header = array("Angajat", "Numar marca", "Superior", "Group Leader", "Linie", "Schimb", "Adresa", "Ruta"); 
fputcsv($out, $header,"\t");
fclose($out);
但是,当我尝试打开文件时,出现以下错误:

如果我单击“是”,它将正确打开,在顶部我看到导出保存为“txt”格式。我不知道为什么。有人能帮我解决这个问题吗