From 6799ac90e55d49a8ffd8ae68ff6349599e69eebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 3 Oct 2019 14:27:20 +0200 Subject: [PATCH] Detect correctly if an attachment file is not existing. --- src/Services/AttachmentHelper.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Services/AttachmentHelper.php b/src/Services/AttachmentHelper.php index f22c9245..6e40d38f 100644 --- a/src/Services/AttachmentHelper.php +++ b/src/Services/AttachmentHelper.php @@ -88,8 +88,12 @@ class AttachmentHelper return null; } - $path = $attachment->getPath(); - $path = $this->pathResolver->placeholderToRealPath($path); + $path = $this->pathResolver->placeholderToRealPath($attachment->getPath()); + + //realpath does not work with null as argument + if ($path === null) { + return null; + } return realpath($path); } @@ -112,7 +116,7 @@ class AttachmentHelper /** * Returns the filesize of the attachments in bytes. - * For external attachments, null is returned. + * For external attachments or not existing attachments, null is returned. * * @param Attachment $attachment The filesize for which the filesize should be calculated. * @return int|null @@ -123,7 +127,12 @@ class AttachmentHelper return null; } - return filesize($this->toAbsoluteFilePath($attachment)); + if (!$this->isFileExisting($attachment)) { + return null; + } + + $tmp = filesize($this->toAbsoluteFilePath($attachment)); + return $tmp !== false ? $tmp : null; } /**