diff --git a/Controllers/UserController.php b/Controllers/UserController.php index 2134123..fa2c2de 100644 --- a/Controllers/UserController.php +++ b/Controllers/UserController.php @@ -111,6 +111,25 @@ final class UserController $O_userModel = new UserModel(); + // TODO harmonize error handling here + if (isset($_FILES["profilPicture"])) { + + if ($_FILES['profilPicture']['error'] !== UPLOAD_ERR_OK) { + die("Upload failed with error code " . $_FILES['profilPicture']['error']); + } + + $info = getimagesize($_FILES['profilPicture']['tmp_name']); + if ($info === false) { + die("Unable to determine image type of uploaded file"); + } + + if (($info[2] !== IMAGETYPE_JPEG) && ($info[2] !== IMAGETYPE_PNG)) { + die("Not a jpeg/png"); + } + + $fp = fopen($_FILES['profilPicture']['tmp_name'], 'rb'); + $O_userModel->updateProfilePicByID($_SESSION["ID"], $fp); + } if (isset($_POST["email"])) { $S_email = $_POST["email"]; if (!empty($S_email) && filter_var($S_email, FILTER_VALIDATE_EMAIL)) { @@ -124,7 +143,7 @@ final class UserController } } - header("Location: /user"); + // header("Location: /user"); } public function deleteAction(Array $A_urlParams = null, Array $A_postParams = null) diff --git a/Models/UserModel.php b/Models/UserModel.php index 511effc..5119335 100644 --- a/Models/UserModel.php +++ b/Models/UserModel.php @@ -58,6 +58,14 @@ final class UserModel extends UserSessionModel return $row["USERNAME"]; } + public function updateProfilePicByID($I_id, $profile_pic_fp){ + $O_model = Model::get(); + $stmt = $O_model->prepare("UPDATE USER SET PROFILE_PIC=:profile_pic WHERE ID=:id"); + $stmt->bindParam("id", $I_id); + $stmt->bindParam("profile_pic", $profile_pic_fp, PDO::PARAM_LOB); + $stmt->execute(); + } + public function updateEmailByID($I_id, $S_newEmail){ $O_model = Model::get(); $stmt = $O_model->prepare("UPDATE USER SET EMAIL=:new_email WHERE ID=:id"); diff --git a/Views/user/edit.php b/Views/user/edit.php index ca2a9bf..3bd2f13 100644 --- a/Views/user/edit.php +++ b/Views/user/edit.php @@ -9,7 +9,7 @@ Se déconnecter -