For some reason the function set_file() and save_profile_pic() just don't seem to actually be running and I can't figure out why. The functions themselves work fine as they work when creating a new user, but for some reason they don't work here.
I have also tried this:
if(!$user -> set_file($_FILES['profile_pic'])) {
redirect("somewherenonexistant.php");
}
and also:
if($user -> set_file($_FILES['profile_pic'])) {
redirect("somewherenonexistant.php");
}
Just to see whether set_file() is actually working, but the code is never run... Regardless of whether I test set_file() being true or false, it never gets to that redirect() line... Surely it must be either true or false?!
I literally have absolutely no idea why the code isn't run. Presumably I've been staring at it for too long now and just can't find it, so I really need some help.
Here's the code:
if(!empty($_GET['id'])) {
$user = User::get_by_id($_GET['id']);
if(isset($_POST['update'])) {
if($user) {
$user -> username = $_POST['username'];
$user -> password = $_POST['password'];
$user -> first_name = $_POST['first_name'];
$user -> last_name = $_POST['last_name'];
if(!empty($_FILES['profile_pic']['size'])) {
$user -> set_file($_FILES['profile_pic']);
$user -> save_profile_pic();
$user -> save();
redirect("edit_user.php?id={$user -> id}");
} else {
$user -> save();
}
}
}
} else {
redirect('users.php');
}
and this is the set_file() function:
public function set_file($file) {
if(empty($file) || !$file || !is_array($file)) {
$this -> errors[] = 'No file was uploaded';
return false;
} else if($file['error'] != 0) { //!= 0 == UPLOAD_ERR_OK
$this -> errors[] = $this -> upload_errors[$file['error']];
return false;
} else {
$this -> profile_pic = basename($file['name']);
$this -> tmp_path = $file['tmp_name'];
}
return true;
}
Thanks.