Fixed duplicate uploaded images
This commit is contained in:
parent
97299ae627
commit
9b63ad9820
|
@ -814,6 +814,13 @@ class UserController extends Controller
|
|||
]);
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
|
||||
// Delete the user's current avatar if it exists
|
||||
while (findAvatar($userId) !== "error.error") {
|
||||
$avatarName = findAvatar($userId);
|
||||
unlink(base_path($avatarName));
|
||||
}
|
||||
|
||||
$fileName = $userId . '_' . time() . "." . $profilePhoto->extension();
|
||||
$profilePhoto->move(base_path('assets/img'), $fileName);
|
||||
}
|
||||
|
@ -866,8 +873,10 @@ class UserController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
if (file_exists(base_path('assets/img/background-img/') . $pathinfo)) {
|
||||
File::delete(base_path('assets/img/background-img/') . $pathinfo);
|
||||
// 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));
|
||||
}
|
||||
|
||||
$fileName = $userId . '_' . time() . "." . $customBackground->extension();
|
||||
|
@ -1153,6 +1162,12 @@ class UserController extends Controller
|
|||
// Decode the image data from Base64
|
||||
$imageData = base64_decode($userData['image_data']);
|
||||
|
||||
// Delete the user's current avatar if it exists
|
||||
while (findAvatar(Auth::id()) !== "error.error") {
|
||||
$avatarName = findAvatar(Auth::id());
|
||||
unlink(base_path($avatarName));
|
||||
}
|
||||
|
||||
// Save the image to the correct path with the correct file name and extension
|
||||
$filename = $user->id . '.' . $userExtension;
|
||||
file_put_contents(base_path('assets/img/' . $filename), $imageData);
|
||||
|
|
Loading…
Reference in New Issue