Skip to content

Commit 9e944b2

Browse files
authored
Update ZipArchive.php
Fix unknown method when not using PCLZip library
1 parent 2daa50c commit 9e944b2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/PhpWord/Shared/ZipArchive.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,12 @@ public function pclzipAddFromString($localname, $contents)
297297
$pathRemoved = $this->tempDir;
298298
$pathAdded = $filenameParts['dirname'];
299299

300-
$res = $zip->add($filename, PCLZIP_OPT_REMOVE_PATH, $pathRemoved, PCLZIP_OPT_ADD_PATH, $pathAdded);
300+
if ( ! $this->usePclzip) {
301+
$pathAdded = $pathAdded.'/'.ltrim(str_replace('\\', '/', substr($filename, strlen($pathRemoved))), '/');
302+
$res = $zip->addFromString($pathAdded, $contents);
303+
} else {
304+
$res = $zip->add($filename, PCLZIP_OPT_REMOVE_PATH, $pathRemoved, PCLZIP_OPT_ADD_PATH, $pathAdded);
305+
}
301306

302307
// Remove temp file
303308
@unlink($this->tempDir . DIRECTORY_SEPARATOR . $filenameParts['basename']);

0 commit comments

Comments
 (0)