/
changeprofilepic.php
93 lines (70 loc) · 1.86 KB
/
changeprofilepic.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
<?php
require_once 'core/init.php';
$user = new User();
require_once 'core/checkLogin.php';
if(!$user->isLoggedIn()){
Redirect::to('index.php');
}else{
if(Input::exists()){
if(Token::check(Input::get('token'))){
if(isset($_FILES['profile_image'])){
if(empty($_FILES['profile_image']['name'])){
$errors[] = 'Please choose a file';
}else{
$image = new Image($_FILES['profile_image']);
$img = $image->check();
if($img->passed()){
$img->store('images/profile/');
$file_path = $img->getFilePath();
try{
$user->update(array(
'image' => $file_path
));
Session::flash('home', 'Your profile image was successfully updated!');
Redirect::to('dashboard.php');
}catch(Exception $e){
die($e->getMessage());
}
}
}
}
}
}
}
include 'includes/header.php';
?>
<div class="header-wrapper">
<div class="header-container">
<h3>Profile Image</h3>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<div class="row">
<div class="large-6 columns">
<?php
if(!empty($user->data()->image)){
echo '<img style="width: 150px;" src="'.$user->data()->image.'" alt="Profile Image" >';
}
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="profile_image">
<input type="hidden" name="token" value="<?= Token::generate(); ?>">
<input type="submit" class="button" value="Submit">
<a class="button alert" href="dashboard.php">Back</a>
</form>
<?php
if(!empty($errors)){
output_errors($errors);
}
if(isset($img) && !$img->passed() && !empty($img->errors())){
output_errors($img->errors());
}
?>
</div>
</div>
</div>
</div>
<?php
include 'includes/footer.php';
?>