Repository navigation
Expand file tree
/
Copy pathchangesettings.php
More file actions
executable file
·99 lines (85 loc) · 2.99 KB
/
Copy pathchangesettings.php
File metadata and controls
executable file
·99 lines (85 loc) · 2.99 KB
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
<?php
include 'core/init.php';
protect_page();
if(empty($_POST) == false) {
$fields = array('name', 'email');
foreach($_POST as $key=>$value) {
if(empty($value) && in_array($key, $fields) == true){
$errors[] = 'All fields are required';
break 1;
}
}
$_POST['name'] = htmlspecialchars($_POST['name'], ENT_QUOTES);
$_POST['email'] = htmlspecialchars($_POST['email'], ENT_QUOTES);
$avatar = (empty($_FILES['avatar']['name']) == false) ? true : false;
if(empty($errors) == true) {
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) == false) {
$errors[] = 'A valid email adress is required';
}
if(email_exists($_POST['email']) === true && $_POST['email'] !== $user_data['email']) {
$errors[] = 'Sorry, the email \'' . $_POST['email'] . '\' is already in use';
}
if($avatar == true) {
$allowed_extensions = array("png", "jpg", "jpeg");
$file_name = $_FILES['avatar']['name'];
$file_extension = explode(".", $file_name);
$file_extension = strtolower(end($file_extension));
$file_temp = $_FILES['avatar']['tmp_name'];
if(in_array($file_extension, $allowed_extensions) !== true) {
$errors[] = "Incorrect file type.";
}
list($avatar_width, $avatar_height) = getimagesize($file_temp);
if($avatar_width > 100 || $avatar_height > 100) {
$errors[] = "Your image is too big!";
}
}
}
}
include 'includes/overall/header.php';
?>
<h2>Profile Settings</h2>
<?php
if(isset($_GET['success']) && empty($_GET['success'])) {
echo '<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Congratulations!</strong> The profile settings were successfully updated ! <a href="changesettings.php"> Back </a></div>';
} else {
if(empty($_POST) == false && empty($errors) == true) {
if($avatar == true) {
send_avatar($file_temp, $file_extension);
$update_data = array(
'name' => $_POST['name'],
'email' => $_POST['email'],
'avatar' => $file_path
);
unlink($user_data['avatar']);
} else {
$update_data = array(
'name' => $_POST['name'],
'email' => $_POST['email']
);
}
update_user($_SESSION['user_id'], $update_data);
header('Location: changesettings.php?success');
} else if (empty($errors) == false) {
echo output_errors($errors);
}
?>
<form action="" method="post" enctype="multipart/form-data">
<label>Avatar</label>
<?php if(empty($user_data['avatar']) == false) {
echo "<img src='" . $user_data['avatar'] . "' alt='" . $user_data['name'] . "' />";
}
?><br />
<input type="file" name="avatar" />
<label>Name</label>
<input type="text" name="name" value="<?php echo $user_data['name']; ?>" />
<label>Email</label>
<input type="text" name="email" value="<?php echo $user_data['email']; ?>" />
<br />
<input class="btn btn-primary" type="submit" value="Submit Settings" />
</form>
<?php
}
include 'includes/overall/footer.php';
?>