old avatar fix

This commit is contained in:
flash 2015-08-09 21:19:11 +02:00
parent 4404c6ea42
commit c1f63a49f2
2 changed files with 12 additions and 0 deletions

View file

@ -1661,6 +1661,10 @@
{
"type": "ADD",
"change": "Added avatar uploading (background uploads soon)."
},
{
"type": "FIX",
"change": "Fixed old avatars not getting deleted."
}
]

View file

@ -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]);