This repository has been archived by the owner on Nov 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditProfile.php
118 lines (97 loc) · 3.72 KB
/
editProfile.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
<?php
//The method used to update the profile bio and picture is taken from the book Learning PHP, MySQL, JavaScript, and CSS: A Step-by-Step Guide to Creating Dynamic Websites By Robin Nixon
include_once 'head.php';
include_once 'login.php';
echo "<div class = 'main'><h3>Your Profile</h3>";
$somethingChanged = false;
if(isset($_POST['text']))
{
$text = sanitizeString($_POST['text']);
$text = preg_replace('/\s\s+/', ' ', $text);
$result = makeQuery("SELECT * FROM doctorProfiles WHERE username = '$user'");
if(mysql_num_rows($result))
{
makeQuery("UPDATE doctorProfiles SET bio='$text' WHERE username='$user'");
}
else
{
makeQuery("INSERT INTO doctorProfiles VALUES ('$user', '$text', '0', '0')");
}
$somethingChanged = true;
}
$result = makeQuery("SELECT * FROM doctorProfiles WHERE username= '$user'");
if(mysql_num_rows($result))
{
$row = mysql_fetch_row($result);
$textOutput = sanitizeString($row[1]);
}
else
{
$textOutput = "";
}
$textOutput = sanitizeString(preg_replace('/\s\s+/', ' ', $textOutput));
if(isset($_FILES['image']['name']))
{
$saveAs = "profilePhotos/$user.jpg";
move_uploaded_file($_FILES['image']['tmp_name'], $saveAs);
$typeOkay = true;
switch ($_FILES['image']['type'])
{
case "image/gif": $src = imagecreatefromgd($saveAs);
break;
case "image/jpeg":
case "image/jpeg": $src = imagecreatefromjpeg($saveAs);
break;
case "image/png": $src = imagecreatefrompng($saveAs);
break;
default: $typeOkay = false;
break;
}
if ($typeOkay)
{
list($width, $height) = getimagesize($saveAs);
$max = 300;
$trueHeight = $height;
$trueWidth = $width;
if($width > $height && $max < $width)
{
$trueHeight = $max / $width * $height;
$trueWidth = $max;
}
else if ($height > $width && $max < $height)
{
$trueWidth = $max / $height * $width;
$trueHeight = $max;
}
else if($max < $width || $max < $height)
{
$trueWidth = $trueHeight = $max;
}
$tmpImage = imagecreatetruecolor($trueWidth, $trueHeight);
imagecopyresampled($tmpImage, $src, 0, 0, 0, 0, $trueWidth, $trueHeight, $width, $height);
imageconvolution($tmpImage, array(array(-1, -1, -1), array(-1, 16, -1),
array(-1, -1, -1)), 8, 0);
imagejpeg($tmpImage, $saveAs);
imagedestroy($tmpImage);
imageDestroy($src);
$somethingChanged = true;
}
}
if ($somethingChanged)
{
echo "<span class='successfulUpdate'>You have Successfully Updated".
"your Profile, To view it, click ".
"<a href = 'viewProfile.php?userToDisplay=$user'>here</a>";
}
echo <<<_END
<div class='sixty' align='center'><div style='width:30%;'>
<form method='post' action='editProfile.php' enctype='multipart/form-data'>
<h4>Enter or Edit Your Profile Details</h4>
<span style='font-size:1.4em'>Your Bio</span><br />
<textarea name='text' cols='50' rows='3'>$textOutput</textarea><br /><BR>
_END;
?>
<span style='font-size:1.4em' class = 'addphoto'>Add a photo </span><input class='form-control' type = 'file' name = 'image' size = '14' maxlength = '32'/><BR>
<input class='btn btn-success' type = 'submit' value = 'Save Profile Changes'/>
</form></div></div></div></body><html>
104,22-25 Bot