我在这里遇到了与@pindol相同的问题。
我在页面问题中遵循了用户提供的一些步骤。因此,我测试了 TemplateProcessor 中的函数以查看输出,最后,使用 var_dump 测试了 $TemplateProcessor 漏洞:
object(PhpOffice\PhpWord\TemplateProcessor)#1259 (9) { ["zipClass":protected]=> object(PhpOffice\PhpWord\Shared\ZipArchive)#1008 (5) { ["numFiles"]=> int(11) ["filename"]=> string(18) "/tmp/PhpWord5qX68E" ["tempDir":"PhpOffice\PhpWord\Shared\ZipArchive":private]=> string(4) "/tmp" ["zip":"PhpOffice\PhpWord\Shared\ZipArchive":private]=> object(PclZip)#1046 (5) { ["zipname"]=> string(18) "/tmp/PhpWord5qX68E" ["zip_fd"]=> int(0) ["error_code"]=> int(0) ["error_string"]=> string(0) "" ["magic_quotes_status"]=> int(-1) } ["usePclzip":"PhpOffice\PhpWord\Shared\ZipArchive":private]=> bool(true) } ["tempDocumentFilename":protected]=> string(18) "/tmp/PhpWord5qX68E" ["tempDocumentMainPart":protected]=> string(2690) " Test : the test is perfect" ["tempDocumentSettingsPart":protected]=> string(2842) " " ["tempDocumentHeaders":protected]=> array(0) { } ["tempDocumentFooters":protected]=> array(0) { } ["tempDocumentRelations":protected]=> array(1) { ["word/document.xml"]=> string(817) " " } ["tempDocumentContentTypes":protected]=> string(1312) " " ["tempDocumentNewImages":protected]=> array(0) { } }
正如我们在 ["tempDocumentMainPart":protected] 中看到的,变量已成功替换为以下函数:
$templateProcessor = new TemplateProcessor('results/test.docx');
$templateProcessor->setValue('test', 'the test is perfect');
var_dump($templateProcessor);
exit();
$templateProcessor->saveAs('results/results.docx');
return response()->download('results/results.docx');
但是当我尝试另存为或下载文件时,下载的文件中的变量没有更改。它与提供的模板相同,当我尝试打开它时收到一条错误消息(下载后):
Word found unreadable content in results.docx. Do you want to recover the contents of this document? If the source for this document is reliable, click Yes.
我在 PhpWord 0.16.0 和 0.17.0 中对此进行了测试,并将其与 laravel 一起使用(我不认为问题出在 laravel 上)。PHP版本:
PHP 7.4.7 (cli) (built: Jun 12 2020 07:48:26) ( NTS )
我使用 PCLZIP 而不是 zipArchive,因为它会产生内存问题。提前致谢
婷婷同学_
慕田峪7331174
随时随地看视频慕课网APP