找不到存档文件。在 PHPWord-0.16.0/vendor/phpoffice/common/src/Common/XMLReader.php

Cannot find archive file. in PHPWord-0.16.0/vendor/phpoffice/common/src/Common/XMLReader.php

我想在 php 中将 docx 文件转换为 html 并将内容作为 json 响应发送到 angular 端。 我正在尝试来自 here

的代码
require_once 'bootstrap.php';
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$objReader = \PhpOffice\PhpWord\IOFactory::createReader('Word2007');
$phpWord = $objReader->load("http://192.168.11.13/local/courses/5c2c5f8d810f9.docx");
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
$objWriter->save('helloWorld.html');

我正在尝试这段代码,我哪里出错了?我已启用 allow_url_include。 抛出错误,

Fatal error: Uncaught Exception: Cannot find archive file. in /var/www/html/PHPWord-0.16.0/vendor/phpoffice/common/src/Common/XMLReader.php:51 Stack trace: #0 /var/www/html/PHPWord-0.16.0/src/PhpWord/Reader/Word2007.php(147): PhpOffice\Common\XMLReader->getDomFromZip('http://192.168....', '_rels/.rels') #1 /var/www/html/PHPWord-0.16.0/src/PhpWord/Reader/Word2007.php(112): PhpOffice\PhpWord\Reader\Word2007->getRels('http://192.168....', '_rels/.rels') #2 /var/www/html/PHPWord-0.16.0/src/PhpWord/Reader/Word2007.php(42): PhpOffice\PhpWord\Reader\Word2007->readRelationships('http://192.168....') #3 /var/www/html/PHPWord-0.16.0/test_word.php(14): PhpOffice\PhpWord\Reader\Word2007->load('http://192.168....') #4 {main} thrown in /var/www/html/PHPWord-0.16.0/vendor/phpoffice/common/src/Common/XMLReader.php on line 51

一个可能的解决方案是,您可以检查文件权限,根据 PHPWord 代码的要求,检查文件夹是否具有创建存档文件的权限。

为您的应用程序文件夹添加 777 权限。也许这将解决上述问题。