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()); }