From c8c0f49b75f7e33d52000217f44ae2cbbe69e439 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 15 Jul 2021 17:52:48 -0700 Subject: [PATCH] Dont download image if not needed (#10) --- src/Service/LocalImageUploader.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Service/LocalImageUploader.php b/src/Service/LocalImageUploader.php index 6820b07..b8fde8e 100644 --- a/src/Service/LocalImageUploader.php +++ b/src/Service/LocalImageUploader.php @@ -29,18 +29,17 @@ public function __construct(string $uploadsFolder, string $webPrefix) public function uploadImage(string $url): string { - //Download the file - $file = @\file_get_contents($url); - if (false === $file) { - return ''; - } - $filename = \basename($url); - $path = \sprintf('%s/%s', $this->uploadsFolder, $filename); // Check if file already exists if (!\file_exists($path)) { + //Download the file + $file = @\file_get_contents($url); + if (false === $file) { + return ''; + } + // Save the file @\mkdir(\dirname($path)); \file_put_contents($path, $file);