Skip to content

Commit

Permalink
Create updatePicture
Browse files Browse the repository at this point in the history
  • Loading branch information
chukitipok authored May 1, 2018
1 parent 4e7176b commit e429b16
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions script/updatePicture
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

session_start();
require "../conf.inc.php";
require "../functions.php";


if (isset($_POST['updatePicture']) && !empty($_POST['updatePicture'])){
$db = connectDB();
$error = false;
$listeOfErrors = [];
$oldFilename = getInfo('member_picture');
$filename = cleanPictureName($_FILES['newPicture']['name']);

if ($_FILES['newPicture']['size'] != 0){
//file type : jpg, png, jpeg, gif
if (!verifPictureType($_FILES)){
$error = true;
$listeOfErrors[] = 16;
}

//Picture size under 30000 bytes
if (!verifPictureSize($_FILES)){
$error = true;
$listeOfErrors[] = 17;
}
}else{
$filename = null;
}

if($error){
$_SESSION["signUp"] = FALSE;
$_SESSION["errorForm"] = $listeOfErrors;
Location();

}else {
if ($_FILES['newPicture']['size'] > 0) {
uploadPicture($_FILES);
}

if ($oldFilename != null){
deleteProfilePicture($oldFilename);
}

$query = $db->prepare("UPDATE member
SET member_picture = :picture
WHERE member_id = :id AND member_token = :token;");
$query->execute([
"picture" => $filename,
"id" => $_SESSION["id"],
"token" => $_SESSION["token"]
]);
header("Location: ../userSettings.php");
}
}

0 comments on commit e429b16

Please sign in to comment.