From 3d2cd163d385be827b61daabf1c85f8e23af5ad3 Mon Sep 17 00:00:00 2001 From: Andrew Collins Date: Thu, 5 Jun 2014 13:45:18 -0400 Subject: [PATCH] Ensure temp file in pclzipAddFile() removed Make pclzipAddFile() similar to pclzipAddFromString() in removing temporary files. --- src/PhpWord/Shared/ZipArchive.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/PhpWord/Shared/ZipArchive.php b/src/PhpWord/Shared/ZipArchive.php index cbfcb071..8bbfd4c3 100644 --- a/src/PhpWord/Shared/ZipArchive.php +++ b/src/PhpWord/Shared/ZipArchive.php @@ -224,7 +224,9 @@ class ZipArchive // To Rename the file while adding it to the zip we // need to create a temp file with the correct name + $temp_file = false; if ($filenameParts['basename'] != $localnameParts['basename']) { + $temp_file = true; // temp file created $temppath = $this->tempDir . '/' . $localnameParts['basename']; copy($filename, $temppath); $filename = $temppath; @@ -236,6 +238,11 @@ class ZipArchive $res = $zip->add($filename, PCLZIP_OPT_REMOVE_PATH, $pathRemoved, PCLZIP_OPT_ADD_PATH, $pathAdded); + if($temp_file) { + // Remove temp file, if created + @unlink($this->tempDir . '/' . $localnameParts["basename"]); + } + return ($res == 0) ? false : true; }