我有这个代码,它可以在本地运行,但不能直播 - 这将从数据库的查询中接收结果 目前输出只发送到浏览器 - 而不是像本地那样提供下载:
if($_POST['xls'] == 'on'){
$file_type = "vnd.ms-excel";
$file_ending = "xls";
$ttype = date('m-d-Y-H:i:s');
header("Content-Type: application/$file_type");
//header("Content-Type: application/force-download");
//header("Content-Type: application/octet-stream");
//header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=$ttype.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");
}
这两个服务器都是linux,运行带有php 5.2.17的cPanel的实时服务器 我不管理cpanel服务器,无法升级php
由于
答案 0 :(得分:0)
您的文件名似乎没有扩展名。在php中,.
用于连接 - 所以现在你的文件名是09-18-2013-01:31:30xls
。它可能也不喜欢冒号。试试这个:
$ttype = date('m-d-Y-His');
header("Content-Disposition: attachment; filename=".$ttype.".".$file_ending);
答案 1 :(得分:0)
尝试删除
header("Content-Type: application/octet-stream");
这可能会使浏览器将其流式传输到文档中,而不是要求下载。
答案 2 :(得分:0)
试试这个
<?php
$date = date("d/m/Y");
if($_REQUEST['cetak'] == 3){
$file_type = "vnd.ms-excel";
//$file_name= "somename.xls";
header("Content-Type: application/$file_type");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment; filename=Report".$date.".xls");
header("Expires: 0");
header("Pragma: no-cache");
header("Content-Transfer-Encoding: binary");
}
?>