From 9f06ef68c0b59ce7dec285be9de7fc9b417a723b Mon Sep 17 00:00:00 2001 From: Julian Prieber Date: Wed, 7 Feb 2024 15:20:07 +0100 Subject: [PATCH] Improved image delete --- app/Http/Controllers/UserController.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 706aada..d69862a 100755 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -898,13 +898,12 @@ class UserController extends Controller //Delete custom background image public function removeBackground() { + $userId = Auth::user()->id; - $user_id = Auth::user()->id; - $path = findBackground($user_id); - $path = base_path('assets/img/background-img/'.$path); - - if (File::exists($path)) { - File::delete($path); + // Delete the user's current background image if it exists + while (findBackground($userId) !== "error.error") { + $avatarName = "assets/img/background-img/" . findBackground(Auth::id()); + unlink(base_path($avatarName)); } return back(); @@ -1055,11 +1054,12 @@ class UserController extends Controller //Delete profile picture public function delProfilePicture() { - $user_id = Auth::user()->id; - $path = base_path(findAvatar($user_id)); + $userId = Auth::user()->id; - if (File::exists($path)) { - File::delete($path); + // Delete the user's current avatar if it exists + while (findAvatar($userId) !== "error.error") { + $avatarName = findAvatar($userId); + unlink(base_path($avatarName)); } return back();