0
我有PHP办公室集成在一个laravel应用程序。它运行在我的xampp本地主机上,但是当我在IIS生产服务器上使用它时,我得到“我们很抱歉,我们无法打开text.docx,因为我们发现它的内容有问题。并且无法打开。“我可以通过点击两个错误弹出窗口警告我有关“无法读取的内容”,然后打开文件。当我最终打开它时,该文件看起来很好。 IIS服务器使用PHP版本5.6.14,libxml2版本2.9.2与XML阅读器&作者启用和Zend扩展220131226. 这里是有问题的代码,我拉出部分,仍然有相同的错误,所以我知道它不是我的字符串格式。 也可能相关的是,在两台服务器上,文档都以“读取模式”而不是“打印版式”打开。我宁愿它在打印版式中打开。PHPWord文件在IIS服务器上损坏
$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");