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!