store profile picture in database when uploaded
This commit is contained in:
parent
5cf511a9c9
commit
a4fcfb08e3
@ -111,6 +111,25 @@ final class UserController
|
|||||||
|
|
||||||
$O_userModel = new UserModel();
|
$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"])) {
|
if (isset($_POST["email"])) {
|
||||||
$S_email = $_POST["email"];
|
$S_email = $_POST["email"];
|
||||||
if (!empty($S_email) && filter_var($S_email, FILTER_VALIDATE_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)
|
public function deleteAction(Array $A_urlParams = null, Array $A_postParams = null)
|
||||||
|
@ -58,6 +58,14 @@ final class UserModel extends UserSessionModel
|
|||||||
return $row["USERNAME"];
|
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){
|
public function updateEmailByID($I_id, $S_newEmail){
|
||||||
$O_model = Model::get();
|
$O_model = Model::get();
|
||||||
$stmt = $O_model->prepare("UPDATE USER SET EMAIL=:new_email WHERE ID=:id");
|
$stmt = $O_model->prepare("UPDATE USER SET EMAIL=:new_email WHERE ID=:id");
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<a href="/user/logout">Se déconnecter</a>
|
<a href="/user/logout">Se déconnecter</a>
|
||||||
|
|
||||||
<form action="/user/update" method="post">
|
<form action="/user/update" method="post" enctype="multipart/form-data">
|
||||||
<label for="profilPicture">Changer l'image de profil </label>
|
<label for="profilPicture">Changer l'image de profil </label>
|
||||||
<input type="file" name="profilPicture" id="profilPicture" accept="image/*">
|
<input type="file" name="profilPicture" id="profilPicture" accept="image/*">
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user