From 2ad66102d23dc5a35195579a0ffed4f54eada08e Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 13 Dec 2018 23:14:31 +0200 Subject: [PATCH] FlexMediaTrait: Cropping existing image without original fails to move the original image to safe place --- system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php index 138614303..38b48e4f3 100644 --- a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php +++ b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php @@ -125,6 +125,11 @@ trait FlexMediaTrait } if ($uploadedFile->getError() === \UPLOAD_ERR_OK) { $uploadedFile->moveTo($filepath); + } elseif (!file_exists($filepath) && $pos = strpos($filename, '/')) { + $origpath = sprintf('%s/%s', $path, substr($filename, $pos)); + if (file_exists($origpath)) { + copy($origpath, $filepath); + } } } else { $uploadedFile->moveTo($filepath); @@ -172,7 +177,6 @@ trait FlexMediaTrait } if (file_exists($targetFile)) { - $result = unlink($targetFile); if (!$result) { throw new RuntimeException($language->translate('PLUGIN_ADMIN.FILE_COULD_NOT_BE_DELETED') . ': ' . $filename, 500);