ie导出的excel是php文件,php-IE中的Excel导出问题

我有此脚本将mysql数据导出到excel.我努力了

一切,但我无法使该脚本适用于IE.该

脚本使用FireFox或Chrome下载数据,但IE失败并且

说:

Internet Explorer无法从www.mysite.com下载list_view.php. (这是文件所在的站点).

Internet Explorer无法

打开此Internet网站.请求的站点不可用或

找不到.请稍后再试.

这是我正在使用的代码:

$sql = "SELECT...."

$result = mysql_query($sql)

or die("\nError Retrieving Records.


sql: $sql
ERROR:".mysql_error());

if(mysql_num_rows($result) > 0){

// build a filename that excel will use to save it as

$filename=$name."_".dateFromDB($_GET['confDate']).".xls";

// headers to force the open/save into Excel

header("Content-Type: application/vnd.ms-excel");

header("Content-Disposition: attachment; filename=$filename");

header("Pragma: no-cache");

header("Expires: 0");}?>

addressphoneemailstatus

while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { ?>

=$row['address'];?>=$row['phone'];?>=$row['email'];?>=$row['status'];?><?php

}?>

<?php

exit(); // exit or it will throw an error when it tries to continue

我知道也许有人建议不要使用IE,但是实际上正在使用导出功能的人无法访问其他浏览器.

编辑:

我忘了提到我正在运行SSL(https).如果我关闭SSL,则在IE上一切正常,但在IE上显示SSL时显示错误.

任何想法如何使其在SSL下工作?

解决方法:

标头使用IE可能比较棘手.这是东西,您应该将其设置为不像这样缓存:

ini_set('zlib.output_compression','Off');

header('Pragma: public');

header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

//header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1

header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1

header ("Pragma: no-cache");

header("Expires: 0");

现在可能会有一个问题,如果您的服务器时间未设置为正确的时区,则实际上可能会产生相反的效果,并迫使IE对其进行缓存.确保您的时区设置为您所在的正确时区.它是共享服务器吗?你有ssh访问权限吗?

Excel标头

现在,您需要为IE提供一组标头

header('Content-Transfer-Encoding: none');

header('Content-Type: application/vnd.ms-excel;'); // This should work for IE & Opera

header("Content-type: application/x-msexcel"); // This should work for the rest

header('Content-Disposition: attachment; filename="'.basename($filename).'"');

尝试一下,希望它能工作.

标签:export-to-excel,php,mysql,ssl,excel

来源: https://codeday.me/bug/20191010/1885530.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值