-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdatePicture
55 lines (46 loc) · 1.62 KB
/
updatePicture
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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");
}
}