From d0e7aed1556308cffb1c11d8c6ad5d3ef1b5f942 Mon Sep 17 00:00:00 2001 From: todstoychev Date: Wed, 11 Nov 2015 12:56:30 +0200 Subject: [PATCH] Fixed delete image issue. --- src/Handler/DeleteImageHandler.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Handler/DeleteImageHandler.php b/src/Handler/DeleteImageHandler.php index 5245a7b..0bc91be 100644 --- a/src/Handler/DeleteImageHandler.php +++ b/src/Handler/DeleteImageHandler.php @@ -24,14 +24,14 @@ public function deleteImageSizes($context, $fileName) $contextPath = public_path($this->getUploadsPath() . '/' . $context); foreach ($this->getContextValues($context) as $key => $value) { - $image = $contextPath . '/' . $context . '/' . $fileName; + $image = $contextPath . '/' . $key . '/' . $fileName; is_file($image) ? unlink($image) : null; } } /** - * Copletely deletes an image + * Completely deletes an image * * @param string $context * @param string $fileName @@ -42,8 +42,12 @@ public function deleteImage($context, $fileName) { $this->deleteImageSizes($context, $fileName); - $originalImage = public_path($this->getUploadsPath() . '/' . $context . '/' . $fileName); + $fileName = preg_replace('/\.[a-z]{3,4}/', '', $fileName); - is_file($originalImage) ? unlink($originalImage) : null; + $path = public_path($this->getUploadsPath() . '/' . $context); + + foreach (glob($path . '/' . $fileName . '*') as $file) { + unlink($file); + } } } \ No newline at end of file