所以我在这里有这段代码从数据库中读取数据,然后它应该提示我“打开/另存为”窗口,但它没有。知道问题可能出在哪里吗?它会回显结果,但不会出现下载窗口。
<?php/*
mb_http_output('UTF-8');
mb_http_input('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
ob_start('mb_output_handler');
header('Content-type: text/html; charset=utf-8');*/
?>
<?php
$conn = mysql_connect('localhost', 'xxxx', 'xxxx') or die(mysql_error());
mysql_select_db('nooruse', $conn) or die(mysql_error($conn));
$query = sprintf('SELECT osakond as Osakond, soetusaasta, it_number, tooteruhm, mudeli_nimetus, sn, riigivara_nr, inventaari_nr, maja, ruum, vastutaja, markus FROM norse5_proov');
$result = mysql_query($query, $conn) or die(mysql_error($conn));
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=export.csv');
$row = mysql_fetch_assoc($result);
if ($row) {
echocsv(array_keys($row));
}
while ($row) {
echocsv($row);
$row = mysql_fetch_assoc($result);
}
function echocsv($fields)
{
echo $query ,"<br>";
$separator = '';
foreach ($fields as $field) {
if (preg_match('/\\r|\\n|,|"/', $field)) {
$field = '"' . str_replace('"', '""', $field) . '"';
}
echo $separator . $field;
$separator = ',';
}
echo "\r\n";
}
?>
提前致谢!