-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_profile_image.php
284 lines (218 loc) · 9.77 KB
/
change_profile_image.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
session_start();
//print_r();
include("classes/connect.php");
include("classes/login.php");
include("classes/user.php");
include("classes/post.php");
include("classes/image.php");
//isset($_SESSION['NFoster_userid'];
$login = new Login();
$user_data = $login->check_login($_SESSION['NFoster_userid']);
if($_SERVER['REQUEST_METHOD'] == "POST")
{
if(isset($_FILES['file']['name']) && $_FILES['file']['name'] != "")
{
if($_FILES['file']['type'] == "image/jpeg")
{
$allowed_size = (1024 * 1024) * 7;
if($_FILES['file']['size'] < $allowed_size)
{
//fine
$folder = "uploads/" . $user_data['userid'] . "/";
//create folder
if(!file_exists($folder))
{
mkdir($folder, 0777, true);
}
$image = new Image();
$filename = $folder . $image->generate_filename(15) . ".jpg";
move_uploaded_file($_FILES['file']['tmp_name'], $filename);
$change = "profile";
if(isset($_GET['change']))
{
//check for mode
$change = $_GET['change'];
}
if($change == "cover")
{
if(file_exists($user_data['cover_image']))
{
unlink(user_data['cover_image']);
}
$image->resize_image($filename,$filename,1500,1500);
}
else
{
if(file_exists($user_data['profile_image']))
{
unlink(user_data['profile_image']);
}
$image->crop_image($filename,$filename,1500,1500);
}
if(file_exists($filename))
{
$userid = $user_data['userid'];
if($change == "cover")
{
$query = "update users set cover_image = '$filename' where userid = '$userid' limit 1 ";
}else
{
$query = "update users set profile_image = '$filename' where userid = '$userid' limit 1 ";
}
$DB = new Database();
$DB->save($query);
header("Location: profile.php");
die;
}
}else
{ //echo"<div style='text-align:center; font-size: 12px; color:black; backgroud-color:blue;'>";
//echo "<br>Following Errors are occures<br>";
//echo "Please enter Image of a size 7mb or Lower are allowed !";
//echo"</div>";
echo "<script> alert('Please enter Image of a size 7mb or Lower are allowed !'); </script>";
}
}else
{
//echo"<div style='text-align:center; font-size: 12px; color:black; backgroud-color:blue;'>";
//echo "<br>Following Errors are occures<br>";
//echo "Please enter only jpeg type Image!";
//echo"</div>";
echo "<script> alert('Please enter only jpeg type Image!'); </script>";
}
}else
{
// echo"<div style='text-align:center; font-size: 12px; color:black; backgroud-color:blue;'>";
//echo "<br>Following Errors are occures<br>";
//echo "Please enter a valid Image!";
echo "<script> alert('Please enter a valid Image!'); </script>";
//echo"</div>";
}
}
?>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>N.F - Network Foster</title>
<meta name="robots" content="noindex, follow" />
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Favicon -->
<link rel="shortcut icon" type="image/x-icon" href="assets/images/favicon.ico">
<!-- CSS
============================================ -->
<!-- google fonts -->
<link href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i,900" rel="stylesheet">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="assets/css/vendor/bootstrap.min.css">
<!-- Icon Font CSS -->
<link rel="stylesheet" href="assets/css/vendor/bicon.min.css">
<!-- Flat Icon CSS -->
<link rel="stylesheet" href="assets/css/vendor/flaticon.css">
<!-- audio & video player CSS -->
<link rel="stylesheet" href="assets/css/plugins/plyr.css">
<!-- Slick CSS -->
<link rel="stylesheet" href="assets/css/plugins/slick.min.css">
<!-- nice-select CSS -->
<link rel="stylesheet" href="assets/css/plugins/nice-select.css">
<!-- perfect scrollbar css -->
<link rel="stylesheet" href="assets/css/plugins/perfect-scrollbar.css">
<!-- light gallery css -->
<link rel="stylesheet" href="assets/css/plugins/lightgallery.min.css">
<!-- Main Style CSS -->
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<!-- header area start -->
<header>
<div class="header-top sticky bg-white d-none d-lg-block">
<div class="container">
<div class="row align-items-center">
<div class="col-md-5">
<!-- header top navigation start -->
<div class="header-top-navigation">
<nav>
</nav>
</div>
<!-- header top navigation start -->
</div>
<div class="col-md-2">
<!-- brand logo start -->
<div class="brand-logo text-center">
<a href="main.php">
<img src="assets\images\logo\logo.JPG" alt="brand logo">
</a>
</div>
<!-- brand logo end -->
</div>
</div>
</div>
</div>
</header>
<!-- header area end -->
<!-- header area end -->
<main>
<div class="main-wrapper pt-80">
<div class="container">
<div class="row">
<div class="col-lg-3 order-2 order-lg-1">
<aside class="widget-area">
</aside>
</div>
<div class="col-lg-6 order-1 order-lg-2">
<!-- share box start -->
<!-- Change profile picture starts-->
<div class="card card-small">
<div class="share-box-inner">
<div class="share-content-box w-100">
<form method = "post" enctype="multipart/form-data" class = "share-text-box">
<input type="file" name="file">
<input type="submit" value = "Change" class ="btn-share">
<br><br>
<?php
$change = "profile";
if(isset($_GET['change']) && $_GET['change'] == "cover")
{
//check for mode
$change = "cover";
echo "<img src = '$user_data[cover_image]' > ";
}else
{
echo "<img src = '$user_data[profile_image]' > ";
}
?>
</form>
</div>
<!-- Change profile picture Po-up Ends-->
</div>
</div>
</main>
<!-- JS
============================================ -->
<!-- Modernizer JS -->
<script src="assets/js/vendor/modernizr-3.6.0.min.js"></script>
<!-- jQuery JS -->
<script src="assets/js/vendor/jquery-3.3.1.min.js"></script>
<!-- Popper JS -->
<script src="assets/js/vendor/popper.min.js"></script>
<!-- Bootstrap JS -->
<script src="assets/js/vendor/bootstrap.min.js"></script>
<!-- Slick Slider JS -->
<script src="assets/js/plugins/slick.min.js"></script>
<!-- nice select JS -->
<script src="assets/js/plugins/nice-select.min.js"></script>
<!-- audio video player JS -->
<script src="assets/js/plugins/plyr.min.js"></script>
<!-- perfect scrollbar js -->
<script src="assets/js/plugins/perfect-scrollbar.min.js"></script>
<!-- light gallery js -->
<script src="assets/js/plugins/lightgallery-all.min.js"></script>
<!-- image loaded js -->
<script src="assets/js/plugins/imagesloaded.pkgd.min.js"></script>
<!-- isotope filter js -->
<script src="assets/js/plugins/isotope.pkgd.min.js"></script>
<!-- Main JS -->
<script src="assets/js/main.js"></script>
</body>
</html>