我写了下面的代码来下载php程序中的文件:
if (isset($_GET["action"]) && $_GET["action"] == "GenerateExcel")
{
$events = Activities::RetDaily($date);
$file = "../temp/DailyReport.csv";
header ("Content-Type: application/download");
header ("Content-Disposition: attachment; filename=$file");
header("Content-Length: " . ($fsize));
readfile($file);
}
我使用下面的脚本提交表单:
function GenerateExcel()
{
document.getElementById("Show").value = "<?php echo $showType ?>";
document.getElementById("action").value= "GenerateExcel";
document.getElementById("DailyReport").submit();
}
当我下载目标文件时,页面的html源代码附加到我的目标文件中!我该怎么做才能解决这个问题?