From c1f63a49f2d4c1e9a2da770d123dc0068cbc693d Mon Sep 17 00:00:00 2001 From: flashwave Date: Sun, 9 Aug 2015 21:19:11 +0200 Subject: [PATCH] old avatar fix --- _sakura/changelog.json | 4 ++++ main/settings.php | 8 ++++++++ 2 files changed, 12 insertions(+) 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]);