From e9cd17d4c7bc0ab4df09e858284369dbf7a98fff Mon Sep 17 00:00:00 2001 From: Maarten de Keizer Date: Tue, 4 Jan 2022 10:22:38 +0100 Subject: [PATCH] Add destructor wich will try to clean up temp file of the template processor --- src/PhpWord/TemplateProcessor.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index 3f7770d3..efabe423 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -132,6 +132,14 @@ class TemplateProcessor $this->tempDocumentContentTypes = $this->zipClass->getFromName($this->getDocumentContentTypesName()); } + public function __destruct() + { + // if the temp file still exists, remove it when running destruct + if ($this->tempDocumentFilename && file_exists($this->tempDocumentFilename) && is_writable($this->tempDocumentFilename)) { + @unlink($this->tempDocumentFilename); + } + } + /** * Expose zip class *