Skip to content

Commit bc6b40d

Browse files
committed
Merge branch 'fix-rare-pclzip-temp-file-issue' of github.com:andrew-kzoo/PHPWord into develop
2 parents 7bbaab3 + 3d2cd16 commit bc6b40d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/PhpWord/Shared/ZipArchive.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ public function pclzipAddFile($filename, $localname = null)
227227

228228
// To Rename the file while adding it to the zip we
229229
// need to create a temp file with the correct name
230+
$temp_file = false;
230231
if ($filenameParts['basename'] != $localnameParts['basename']) {
232+
$temp_file = true; // temp file created
231233
$temppath = $this->tempDir . '/' . $localnameParts['basename'];
232234
copy($filename, $temppath);
233235
$filename = $temppath;
@@ -239,6 +241,11 @@ public function pclzipAddFile($filename, $localname = null)
239241

240242
$res = $zip->add($filename, PCLZIP_OPT_REMOVE_PATH, $pathRemoved, PCLZIP_OPT_ADD_PATH, $pathAdded);
241243

244+
if($temp_file) {
245+
// Remove temp file, if created
246+
@unlink($this->tempDir . '/' . $localnameParts["basename"]);
247+
}
248+
242249
return ($res == 0) ? false : true;
243250
}
244251

0 commit comments

Comments
 (0)