标题("内容 - 处置:附件)无效

时间:2017-07-22 02:55:57

标签: php html mysql export-to-excel lamp

我试图将mysql数据结果导出到excel。点击Export按钮后,表单会将参数的值发送到doexport.php。 结果出现在控制台中。

enter image description here

<?php
session_start(); //Start the session
include('install_lang_japanese.php');

//connect to database
$dbc=mysqli_connect(_SRV,_ACCID,_PWD,"QPL");
if(!$dbc){
   die('Connect Error: ' . mysqli_connect_error());
}

if(isset($_POST['action'])){
   switch($_POST['action']){
      case 'senddatacar':

         $start = mysqli_real_escape_string($dbc,$_POST['startdate']);
         $end = mysqli_real_escape_string($dbc,$_POST['enddate']);

         $sqlex = "SELECT * FROM table";
         $result =mysqli_query($dbc,$sqlex) or die(_ERROR30.":".mysqli_error($dbc));

         $filename="cardata".date('ymd').".xls";

         header("Content-type: application/vnd.ms-excel; name='excel'");
         header(sprintf("Content-Disposition: attachment; filename=$filename"));
         header("Pragma: no-cache");
         header("Expires: 0");

         //Then echo table
         break;
    }
mysqli_close($dbc);
}

我的问题是:我没有看到任何文件已下载为excel

控制台的响应标头:

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:keep-alive
Content-Disposition:attachment; filename=cardata170929.xls
Content-Length:2988
Content-Type:application/vnd.ms-excel; name='excel'
Date:Fri, 29 Sep 2017 05:02:19 GMT
Expires:0
Pragma:no-cache
Server:Apache/2.2.22 (Ubuntu)

0 个答案:

没有答案