Improved image delete

This commit is contained in:
Julian Prieber 2024-02-07 15:20:07 +01:00
parent 85fecf2222
commit 9f06ef68c0
1 changed files with 10 additions and 10 deletions

View File

@ -898,13 +898,12 @@ class UserController extends Controller
//Delete custom background image //Delete custom background image
public function removeBackground() public function removeBackground()
{ {
$userId = Auth::user()->id;
$user_id = Auth::user()->id; // Delete the user's current background image if it exists
$path = findBackground($user_id); while (findBackground($userId) !== "error.error") {
$path = base_path('assets/img/background-img/'.$path); $avatarName = "assets/img/background-img/" . findBackground(Auth::id());
unlink(base_path($avatarName));
if (File::exists($path)) {
File::delete($path);
} }
return back(); return back();
@ -1055,11 +1054,12 @@ class UserController extends Controller
//Delete profile picture //Delete profile picture
public function delProfilePicture() public function delProfilePicture()
{ {
$user_id = Auth::user()->id; $userId = Auth::user()->id;
$path = base_path(findAvatar($user_id));
if (File::exists($path)) { // Delete the user's current avatar if it exists
File::delete($path); while (findAvatar($userId) !== "error.error") {
$avatarName = findAvatar($userId);
unlink(base_path($avatarName));
} }
return back(); return back();