-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathhandleUpdateData.php
118 lines (65 loc) · 2.47 KB
/
handleUpdateData.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
include '../core/init.php';
require_once '../core/classes/validation/Validator.php';
require_once '../core/classes/image.php';
use validation\Validator;
if (User::checkLogIn() === false)
header('location: index.php');
$username = User::getUserNameById($_SESSION['user_id']);
$user =User::getData($_SESSION['user_id']);
$currentImg = $user->img;
$currentCover = $user->imgCover;
if (isset($_POST['update'])) {
$name = User::checkInput($_POST['name']) ;
$bio = User::checkInput($_POST['bio']);
$website = User::checkInput($_POST['website']);
$location = User::checkInput($_POST['location']);
$cover = $_FILES['cover'];
$image = $_FILES['image'];
$v = new Validator;
$v->rules('name' , $name , ['required' , 'string' , 'max:20']);
$v->rules('bio' , $bio , ['string' , 'max:100']);
$v->rules('image' , $image , ['image']);
$v->rules('cover' , $cover , ['image']);
$errors = $v->errors;
if ($errors == []) {
if ($image['name'] !== "") {
$img = new Image($image);
$userImg = $img->new_name ;
} else $userImg = $user->img;
if ($cover['name'] !== "") {
$coverImg = new Image($cover);
$userCover = $coverImg->new_name;
} else $userCover = $user->imgCover;
// var_dump($userCover) ;
// echo "<br>";
// var_dump($userImg) ;
// die();
$data = [
'name' => $name ,
'bio' => $bio ,
'website' => $website ,
'location' => $location ,
'imgCover' => $userCover ,
'img' => $userImg ,
];
$sign= User::update('users' , $_SESSION['user_id'], $data);
if ($sign === true) {
if ($image['name'] !== "") {
if ($currentImg !== 'default.jpg')
unlink('../assets/images/users/' . $currentImg);
$img->upload();
}
if ($cover['name'] !== "") {
if ($currentCover !== 'cover.png')
unlink('../assets/images/users/' . $currentCover);
$coverImg->upload();
}
header('location: ../' . $username);
}
} else {
$_SESSION['errors'] = $errors;
header('location: ../' . $username);
}
} else header('location: ../' . $username);
?>