PHPWord文件在IIS服务器上已损坏


PHPWord file is corrupted on IIS Server

我把PHP办公室集成在一个laravel应用程序中。当我在我的 xampp 本地主机上运行它时它可以工作,但是当我在 IIS 生产服务器上使用它时,我得到"很抱歉,我们无法打开文本.docx因为我们发现它的内容有问题。文件已损坏,无法打开。我可以单击另外两个错误弹出窗口,警告我"不可读的内容",然后打开文件。当我最终打开它时,文件看起来很好。IIS 服务器使用 php 版本 5.6.14、libxml2 版本 2.9.2,启用了 xml 阅读器和编写器,并220131226 Zend Extension 。这是有问题的代码,我拉出了这些部分,但仍然有相同的错误,所以我知道这不是我的字符串格式。同样可能相关的是,在两台服务器上,文档都以"阅读模式"而不是"打印布局"打开。我希望它在打印布局中打开。

$phpWord = new 'PhpOffice'PhpWord'PhpWord();
$phpWord->getCompatibility()->setOoxmlVersion(15);      
$objWriter = 'PhpOffice'PhpWord'IOFactory::createWriter($phpWord, 'Word2007');
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="' . $client->last_name . '.docx"');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
$objWriter->save("php://output");

如果代码适用于XAMPP,我就不会担心代码。尽量与环境相匹配。在IIS上运行PHP与在 Linux 环境中运行不同。