Skip to content

Commit

Permalink
Dont download image if not needed (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm authored Jul 16, 2021
1 parent 04d8f76 commit c8c0f49
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/Service/LocalImageUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c8c0f49

Please sign in to comment.