phpworld替换模板中的变量时会报错求助
"Message": "Could not close zip file : ",
下面返回false,关闭失败报错
// Close zip file
if (false === $this->zipClass->close()) {
throw new Exception('Could not close zip file.'); // @codeCoverageIgnore
}
明明是docx文件呀,为什么会走zip的代码。。。
$tmpPath = '../admin/20210224/1614159814/helloWorld.docx';
if(file_exists($tmpPath)){
// ini_set("pcre.backtrack_limit",1000000);
Settings::loadConfig();
$PHPWord = new \PhpOffice\PhpWord\PhpWord();
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($tmpPath);
$templateProcessor->setValues(array('firstname' => 'John', 'lastname' => 'Doe'));
// foreach($data as $k =>$v){ var_dump($v['key'], $v['value']);die;
// $temp->setValue($v['key'], $v['value']);
// };
$dir = iconv("UTF-8", "GBK", "../admin/20210224/1614159814/");//保存路径
if (!file_exists($dir)){
mkdir ($dir,0777,true); // 如果保存目录不存在就创建新目录
}
$filename = $dir.date(time()).'.docx';
$templateProcessor->saveAs($filename); //另存为新word文档,根据模板和变量生成了新的文档