Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.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 000webhost中生成的csv文件未下载,而是在网页中打印结果。有什么解决办法吗?_Php_Csv_Export To Csv - Fatal编程技术网

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