简体   繁体   English

PhpWord 0.18 未保存且代码引发内部服务器错误

[英]PhpWord 0.18 not saving and code throws an internal sever error

I am trying to create a Word doc in php (7.4) and am using PhpWord 0.18.2.我正在尝试在 php (7.4) 中创建一个 Word 文档,并且正在使用 PhpWord 0.18.2。 All goes fine right up until I save the document.在我保存文档之前一切都很好。 The system throws an HTTP 500 (Internal sever error).系统抛出 HTTP 500(内部服务器错误)。 I have searched for this but could not find anything on it.我已经搜索过这个,但在上面找不到任何东西。 Googleverse and StackOverflow keep pointing me to the follow (or similar) code and none of the results deals with my issue (that I could find). Googleverse 和 StackOverflow 不断将我指向以下(或类似)代码,但没有任何结果涉及我的问题(我可以找到)。 Here it is:这里是:

<?php
echo(__FILE__ . ' ' . __LINE__ . '<br />');
include('../vendor/autoload.php');
echo(__FILE__ . ' ' . __LINE__ . '<br />');
$phpWord = new \PhpOffice\PhpWord\PhpWord();
echo(__FILE__ . ' ' . __LINE__ . '<br />');
// Create the new document..
$phpWord = new \PhpOffice\PhpWord\PhpWord();
echo(__FILE__ . ' ' . __LINE__ . '<br />');
// Add an empty Section to the document
$section = $phpWord->addSection();
echo(__FILE__ . ' ' . __LINE__ . '<br />');
// Add Text element to the Section
$section->addText(
    'Hello World!.'
);
echo(__FILE__ . ' ' . __LINE__ . '<br />');
// Save document
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
echo(__FILE__ . ' ' . __LINE__ . '<br />');
$objWriter->save('HelloWorld.docx');
echo(__FILE__ . ' ' . __LINE__ . '<br />');

I have used the echo statements to determine where the system fails.我已经使用 echo 语句来确定系统出现故障的位置。 Here is the output:这是 output:

/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 2
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 4
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 6
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 9
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 12
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 17
/var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php 20

NOTE: I have tried it without the echo statements (my search mentioned that the file will be corrupt with any echo/print_r statements).注意:我在没有 echo 语句的情况下尝试过(我的搜索提到该文件将被任何 echo/print_r 语句损坏)。 In both cases, it throws the 500 error.在这两种情况下,它都会引发 500 错误。

This has to be something simple, but I just can't see what the issue is.这必须很简单,但我就是看不出问题所在。 The console isn't much help.控制台没有太大帮助。 Any advice on how to troubleshoot 500 errors is welcome.欢迎任何有关如何解决 500 错误的建议。 I'm no sys admin, so a little hand-holding would be appreciated.我不是系统管理员,因此不胜感激。

For those who are noobs, like me:对于像我这样的菜鸟:

more /var/log/apache2/error.log

Will list the errors.将列出错误。 Mine is as follows:我的如下:

[Sun Jan 30 14:43:33.064102 2022] [:error] [pid 17311] [client 10.10.220.32:64626] PHP Fatal error:  Uncaught Error: Class 'ZipArchive' not found in /var/www/intra
/modules/vendor/phpoffice/phpword/src/PhpWord/Shared/ZipArchive.php:135\nStack trace:\n#0 /var/www/intra/modules/vendor/phpoffice/phpword/src/PhpWord/Writer/Abstra
ctWriter.php(285): PhpOffice\\PhpWord\\Shared\\ZipArchive->open('HelloWorld.docx', 8)\n#1 /var/www/intra/modules/vendor/phpoffice/phpword/src/PhpWord/Writer/Word20
07.php(99): PhpOffice\\PhpWord\\Writer\\AbstractWriter->getZipArchive('HelloWorld.docx')\n#2 /var/www/intra/modules/ViventiumFMLAEligibility/PhpWordTest.php(21): P
hpOffice\\PhpWord\\Writer\\Word2007->save('HelloWorld.docx')\n#3 {main}\n  thrown in /var/www/intra/modules/vendor/phpoffice/phpword/src/PhpWord/Shared/ZipArchive.
php on line 135

Looks like I am missing ZipArchive.php in my PhpWord install看起来我在我的 PhpWord 安装中缺少 ZipArchive.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM