Php 000webhost中生成的csv文件未下载,而是在网页中打印结果。有什么解决办法吗?
标题Php 000webhost中生成的csv文件未下载,而是在网页中打印结果。有什么解决办法吗?,php,csv,export-to-csv,Php,Csv,Export To Csv,标题 $file_name = 'data.csv'; sql查询 header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file_name"); header("Content-Type: application/csv;"); $file = fopen('php://output', 'w'); $heade
$file_name = 'data.csv';
sql查询
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Type: application/csv;");
$file = fopen('php://output', 'w');
$header = array("value");
fputcsv($file, $header);
$query=“从日期>=”的数据中选择*”$\u POST[“开始日期”]”和日期
$query = "SELECT * FROM data WHERE date >= '".$_POST["start_date"]."' AND date <= '".$_POST["end_date"]."' ORDER BY packet_id ASC";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row) {
$data = array();
$data[] = $row["value"];
fputcsv($file, $data);
}
fclose($file);
exit;
}