From aee5fb7a9846a58185cf68a4b3d2264cdc991b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 8 Nov 2018 18:55:48 +0100 Subject: [PATCH] Only call fclose if resource is still available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/FileService.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index 543371bf2..ec03db12c 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -157,8 +157,13 @@ class FileService implements IAttachmentService { $target = $folder->newFile($fileName); $content = fopen($file['tmp_name'], 'rb'); + if ($content === false) { + throw new StatusException('Could not read file'); + } $target->putContent($content); - fclose($content); + if (is_resource($content)) { + fclose($content); + } $attachment->setData($fileName); } @@ -175,8 +180,13 @@ class FileService implements IAttachmentService { $target = $this->getFileForAttachment($attachment); $content = fopen($file['tmp_name'], 'rb'); + if ($content === false) { + throw new StatusException('Could not read file'); + } $target->putContent($content); - fclose($content); + if (is_resource($content)) { + fclose($content); + } $attachment->setLastModified(time()); }