diff --git a/_sakura/changelog.json b/_sakura/changelog.json index dc8c57f..8eff1de 100644 --- a/_sakura/changelog.json +++ b/_sakura/changelog.json @@ -1661,6 +1661,10 @@ { "type": "ADD", "change": "Added avatar uploading (background uploads soon)." + }, + { + "type": "FIX", + "change": "Fixed old avatars not getting deleted." } ] diff --git a/main/settings.php b/main/settings.php index 1fb5969..7558afb 100644 --- a/main/settings.php +++ b/main/settings.php @@ -245,6 +245,7 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications // Set path variables $filepath = ROOT .'content/images/user/'; $filename = $filepath .'avatar_'. Session::$userId; + $currfile = !empty($_AVA = Users::getUser(Session::$userId)['userData']['userAvatar']) ? $_AVA : null; // Check if $_FILES is set if(!isset($_FILES['avatar']) && empty($_FILES['avatar'])) { @@ -393,6 +394,13 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications } + // Delete old avatar + if($currfile && file_exists($currfile)) { + + unlink($filepath . $currfile); + + } + // Append extension to filename $filename .= image_type_to_extension($metadata[2]);