Php 开发服务器将页面下载到xls很好,但是

Php 开发服务器将页面下载到xls很好,但是,php,download,Php,Download,我有这个代码,它在本地工作,但不是实时的- 这将从数据库上的查询中接收结果 目前,输出仅发送到浏览器,而不提供下载,就像它在本地所做的那样: 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:

我有这个代码,它在本地工作,但不是实时的- 这将从数据库上的查询中接收结果 目前,输出仅发送到浏览器,而不提供下载,就像它在本地所做的那样:

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,运行cPanel和PHP5.2.17的实时服务器 我不管理cpanel服务器,无法升级php


谢谢

您的文件名似乎没有扩展名。在php中,
用于连接-因此现在您的文件名是
09-18-2013-01:31:30xls
。它可能也不喜欢冒号。试试这个:

$ttype = date('m-d-Y-His');
header("Content-Disposition: attachment; filename=".$ttype.".".$file_ending);
设法除去

header("Content-Type: application/octet-stream");
这可能会使浏览器将其流式传输到文档中,而不是要求下载。

尝试这样做

<?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"); 

}
?>


您需要添加一些内容来影响
readfile(“file.xxx”)
标题之后(“过期:0”)为什么要尝试分配多个内容类型?据我所知,这是不可能的。我在第一个之后添加了3,但现在才意识到这破坏了下载-我已经删除了它们-现在可以在本地工作,而不是在现场still@user1815352试试
标题(“内容类型:application/vnd.openxmlformats of icedocument.spreadsheetml.sheet”)查看是否有帮助。@Fred-尝试过,但没有效果。他应该删除除一种内容类型以外的所有内容类型。关于连接,您有一个观点,但是这个
15:40:43.php
在我的服务器上确实有效。但是,它在Windows平台上不可用。OP应该将冒号改为其他字符,连字符或下划线。