-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadpic.php
More file actions
62 lines (59 loc) · 1.54 KB
/
uploadpic.php
File metadata and controls
62 lines (59 loc) · 1.54 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
<?php
include("config.php");
session_start();
if(isset($_SESSION['uid']) && isset($_SESSION['upass']))
{
$usrid=$_SESSION['uid'];
$upass=$_SESSION['upass'];
}else
{
header("location:index.php");
}
$imagePath="";
$sql="SELECT dp from register where id=$usrid";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
if($count==1)
{
$dp=$row['dp'];
}else
{
header("location:logout.php");
}
$msg="";
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES['userImage']))
{
if (is_uploaded_file($_FILES['userImage']['tmp_name'])) {
$targetPath = $_FILES['userImage']['name'];
$imageFileType = strtolower(pathinfo($targetPath,PATHINFO_EXTENSION));
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
$msg="Please select an image file(.JPG,.JPEG,.PNG).";
}else
{
if($_FILES['userImage']["size"]>5222400)
{
$msg="Image File Too Large.".$_FILES['userImage']["size"];
}else{
if (move_uploaded_file($_FILES['userImage']['tmp_name'], "data/".$usrid.".".$imageFileType))
{
$imagePath="data/".$usrid.".".$imageFileType;
$sql="UPDATE register set dp='$usrid.$imageFileType' where id=$usrid";
$result = mysqli_query($db,$sql);
$msg="Profile Picture Updated Successfully.";
}else
{
$msg="File Upload Error.";
}
}
}
}else
{
echo "Not Uploading.";
}
}else
{
$msg="Please select an image (png/jpg/jpeg).";
}
echo $msg;
?>