From 613087507038a7700661dea53df0ecbc8d9b7c3d Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 1 Sep 2024 17:07:19 +0700 Subject: [PATCH] fix: insert attachments fails if source file from remote URL --- src/Config/Events.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Config/Events.php b/src/Config/Events.php index 9675662..87fab00 100644 --- a/src/Config/Events.php +++ b/src/Config/Events.php @@ -33,8 +33,19 @@ 'disposition' => $attachment['disposition'], 'type' => $attachment['type'], 'multipart' => $attachment['multipart'], - 'bytes' => filesize($attachment['name'][0]), + 'bytes' => getRemoteFileSize($attachment['name'][0]) ?? filesize($attachment['name'][0]), ]); } } }); + +function getRemoteFileSize($url) +{ + $headers = get_headers($url, 1); + + if (isset($headers['Content-Length'])) { + return $headers['Content-Length']; + } + + return false; +}