我想知道如何使用PHPExcel创建文件后重定向页面。创建的文件没问题,但重定向到另一个页面不是。以下是一些代码。创建Excel文件后PHPExcel重定向页面
$excel -> setActiveSheetIndex(0);
$_SESSION["information"] = "Motor Line Checking Completed.";
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment;filename='".$report_name.".xlsx'");
header("Cache-Control: max-age=0");
$writer = PHPExcel_IOFactory::createWriter($excel, "Excel2007");
$writer -> save('php://output');
exit;
header("Location: ".$_SERVER["HTTP_HOST"]."/../../");
exit;
注:
- 如果我删除
exit;
save();
后,XLSX文件将被损坏。 - 如果我在
save();
之前移动header("Location:...");
,它将重定向但不会创建xlsx。 - 我也尝试使用JavaScript重定向。
我想要的是创建xlsx并重定向页面后。
可以让这个excel文件重定向页面后。 –
在这里看到一个参考:http://stackoverflow.com/questions/822707/php-generate-file-for-download-then-redirect – nomistic
嗨@AnowarCst,这是否意味着我必须先重定向并在那里创建文件? – juntapao