@@ -814,6 +814,13 @@ public function editPage(Request $request)
814
814
]);
815
815
816
816
if ($ request ->hasFile ('image ' )) {
817
+
818
+ // Delete the user's current avatar if it exists
819
+ while (findAvatar ($ userId ) !== "error.error " ) {
820
+ $ avatarName = findAvatar ($ userId );
821
+ unlink (base_path ($ avatarName ));
822
+ }
823
+
817
824
$ fileName = $ userId . '_ ' . time () . ". " . $ profilePhoto ->extension ();
818
825
$ profilePhoto ->move (base_path ('assets/img ' ), $ fileName );
819
826
}
@@ -866,10 +873,12 @@ public function themeBackground(Request $request)
866
873
}
867
874
}
868
875
869
- if (file_exists (base_path ('assets/img/background-img/ ' ) . $ pathinfo )) {
870
- File::delete (base_path ('assets/img/background-img/ ' ) . $ pathinfo );
876
+ // Delete the user's current background image if it exists
877
+ while (findBackground ($ userId ) !== "error.error " ) {
878
+ $ avatarName = "assets/img/background-img/ " . findBackground (Auth::id ());
879
+ unlink (base_path ($ avatarName ));
871
880
}
872
-
881
+
873
882
$ fileName = $ userId . '_ ' . time () . ". " . $ customBackground ->extension ();
874
883
$ customBackground ->move (base_path ('assets/img/background-img/ ' ), $ fileName );
875
884
@@ -1152,6 +1161,12 @@ public function importData(Request $request)
1152
1161
if (in_array ($ userExtension , $ allowedExtensions )) {
1153
1162
// Decode the image data from Base64
1154
1163
$ imageData = base64_decode ($ userData ['image_data ' ]);
1164
+
1165
+ // Delete the user's current avatar if it exists
1166
+ while (findAvatar (Auth::id ()) !== "error.error " ) {
1167
+ $ avatarName = findAvatar (Auth::id ());
1168
+ unlink (base_path ($ avatarName ));
1169
+ }
1155
1170
1156
1171
// Save the image to the correct path with the correct file name and extension
1157
1172
$ filename = $ user ->id . '. ' . $ userExtension ;
@@ -1161,7 +1176,7 @@ public function importData(Request $request)
1161
1176
$ user ->image = $ filename ;
1162
1177
}
1163
1178
}
1164
-
1179
+
1165
1180
$ user ->save ();
1166
1181
1167
1182
// Delete all links for the authenticated user
0 commit comments