Can't update avatar from the front-end

Hey,

So I’ve run into a problem with updating user accounts from the front-end. Everything works fine on the registration page.

The following code is used on the register page to upload an user avatar:

$_avatar = $_FILES['picture']['name'];
                    $ext = strtolower(pathinfo($_avatar, PATHINFO_EXTENSION));

                    $filename = implode('.', array(get('username'), $ext));
                    $upload = new Upload(kirby()->roots()->avatars() . DS . $filename, array(
                        'input'     => 'picture',
                        'overwrite' => true
                    ));

While this works like a charm, when updating the user on a diff page, I use this code:

if(isset($_FILES['picture']) && $_FILES['picture'] != null) {
                    $_avatar = $_FILES['picture']['name'];
                    $ext = strtolower(pathinfo($_avatar, PATHINFO_EXTENSION));

                    $filename = implode('.', array(get('username'), $ext));
                    $upload = new Upload(kirby()->roots()->avatars() . DS . $filename, array(
                        'input'     => 'picture',
                        'overwrite' => true
                    ));
                }

I’m checking if the file input is null. If it is, the controller won’t run the upload code. The problem is when I do select a file, the avatar still doesn’t get uploaded.

Does someone have any idea?

Thanks!

I’ve found the issue. First of all, it was a browser caching problem. The avatar wasn’t refresh client-side. The other problem is that at one point I tried to upload a PNG while my avatar was a JPG, so there was no overwrite. I’ll have to delete whatever file name matches the username.