From a9270d73adfd2d0bf35447a478505dee6e759ff0 Mon Sep 17 00:00:00 2001 From: Charlie Bergthaler Date: Thu, 20 Jun 2019 17:21:05 +1200 Subject: [PATCH 1/2] FIX Cleanup temporary file after extracting content in TikaServerTextExtractor and TikaTextExtractor --- src/Extractor/TikaServerTextExtractor.php | 7 ++++++- src/Extractor/TikaTextExtractor.php | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Extractor/TikaServerTextExtractor.php b/src/Extractor/TikaServerTextExtractor.php index be96e0d..c6bcfbf 100644 --- a/src/Extractor/TikaServerTextExtractor.php +++ b/src/Extractor/TikaServerTextExtractor.php @@ -127,6 +127,11 @@ class TikaServerTextExtractor extends FileTextExtractor public function getContent($file) { $tempFile = $file instanceof File ? $this->getPathFromFile($file) : $file; - return $this->getClient()->tika($tempFile); + $content = $this->getClient()->tika($tempFile); + //Cleanup temp file + if ($tempFile instanceof File) { + unlink($tempFile); + } + return $content; } } diff --git a/src/Extractor/TikaTextExtractor.php b/src/Extractor/TikaTextExtractor.php index bda599b..345e093 100644 --- a/src/Extractor/TikaTextExtractor.php +++ b/src/Extractor/TikaTextExtractor.php @@ -80,6 +80,10 @@ class TikaTextExtractor extends FileTextExtractor $path = $file instanceof File ? $this->getPathFromFile($file) : $file; $command = sprintf('tika %s %s', $mode, escapeshellarg($path)); $code = $this->runShell($command, $output); + //Cleanup temp file + if ($path instanceof File) { + unlink($path); + } if ($code == 0) { return $output; From 242e5a307d0b1f6beb3cea31abba370ca50042e4 Mon Sep 17 00:00:00 2001 From: Charlie Bergthaler Date: Wed, 26 Jun 2019 14:30:49 +1200 Subject: [PATCH 2/2] FIX Change check for cleanup of temp files only if file is instance of File. --- src/Extractor/TikaServerTextExtractor.php | 2 +- src/Extractor/TikaTextExtractor.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Extractor/TikaServerTextExtractor.php b/src/Extractor/TikaServerTextExtractor.php index c6bcfbf..28ca93a 100644 --- a/src/Extractor/TikaServerTextExtractor.php +++ b/src/Extractor/TikaServerTextExtractor.php @@ -129,7 +129,7 @@ class TikaServerTextExtractor extends FileTextExtractor $tempFile = $file instanceof File ? $this->getPathFromFile($file) : $file; $content = $this->getClient()->tika($tempFile); //Cleanup temp file - if ($tempFile instanceof File) { + if ($file instanceof File) { unlink($tempFile); } return $content; diff --git a/src/Extractor/TikaTextExtractor.php b/src/Extractor/TikaTextExtractor.php index 345e093..5568351 100644 --- a/src/Extractor/TikaTextExtractor.php +++ b/src/Extractor/TikaTextExtractor.php @@ -81,7 +81,7 @@ class TikaTextExtractor extends FileTextExtractor $command = sprintf('tika %s %s', $mode, escapeshellarg($path)); $code = $this->runShell($command, $output); //Cleanup temp file - if ($path instanceof File) { + if ($file instanceof File) { unlink($path); }