-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.php
More file actions
90 lines (74 loc) · 2.61 KB
/
Copy pathupdate.php
File metadata and controls
90 lines (74 loc) · 2.61 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
<?php
include "config/config.php";
session_start();
if (!isset($_SESSION["email"])) {
header("location: login.php");}
if($_SERVER['REQUEST_METHOD']=='POST'){
$imgFile = $_FILES['user_image']['name'];
$tmp_dir = $_FILES['user_image']['tmp_name'];
$imgSize = $_FILES['user_image']['size'];
if(empty($imgFile)){
$errMSG = true;
echo '<script>alert("Please Select Image File.")</script>';
}
else
{
$upload_dir = 'user_images/';
$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION));
$valid_extensions = array('jpeg', 'jpg', 'png');
$userpic = rand(1000,1000000).".".$imgExt;
if(in_array($imgExt, $valid_extensions)){
if($imgSize < 5000000) {
$stmt1 = mysqli_query($conn,"SELECT usrimg FROM user WHERE email ='".$_SESSION["email"]."'");
if($stmt1){
while($row = mysqli_fetch_array($stmt1))
{
$usrimg = "$row[usrimg]";
unlink("user_images/".$usrimg['userimg']);
}}
move_uploaded_file($tmp_dir,$upload_dir.$userpic);
}
else{
echo '<script>alert("Sorry, your file is too large.")</script>';
}
}
else{
$errMSG = true;
echo '<script>alert("Sorry, only JPG, JPEG, PNG & GIF files are allowed.")</script>';
}
}
if (!isset($errMSG)){
$stmt = mysqli_query($conn, "UPDATE user SET usrimg='".$userpic."' WHERE email='".$_SESSION["email"]."'");
if($stmt){
header("location: page-1.php");
echo '<script>alert("Image Updated Successfully")</script>';
} else {
echo '<script>alert("Cannot complete user registration")</script>';
}
}
}
?>
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<div class="conForm">
<div class="section-header">
<h2>Update Image Form</h2>
</div>
<form name="myform" method="post" enctype="multipart/form-data" action="" >
<span id="ferror" class = "error"></span>
<div>
<h4 style="color: gray; font-size: 16px;">Upload An Image</h4>
<input class="mb-3" type="file" name="user_image" accept="image/*" style="margin-left: 35px; padding: 10px;" /></div>
<div class="mb-3">
</div>
<div ><input type="submit" id="signup" class="submitBnt" name="signup" value="Update" ></div>
</form>
</div>
</body>
</html>