This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
avatar.php
172 lines (164 loc) · 4.39 KB
/
avatar.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
<?
require("include/top.php");
unset($submitok);
if(is_uploaded_file($userfile))
{
//$tmpfile=tempnam("tmp","avatar");
//rename($userfile,$tmpfile);
$size=GetImageSize($userfile);
if($size[0]!=16) {
$errormessage[]="the width must be equal to 16 pixels";
}
if($size[1]!=16) {
$errormessage[]="the height must be equal to 16 pixels";
}
if($size[2]!=1) {
$errormessage[]="the file must be a .gif file";
}
if(filesize($userfile)>4096) {
$errormessage[]="the file size must be lower than 4Kb";
}
$ext = strrchr($userfile_name, '.');
if($ext !== false)
{
$custom_name = substr($userfile_name, 0, -strlen($ext));
}
else
{
$custom_name = $userfile_name;
}
$custom_name = strtolower($custom_name);
if(strlen($custom_name) > 250)
{
$custom_name = substr($custom_name, 0, 250);
}
$custom_name .= '.gif';
if(!preg_match("/^[a-z0-9_-]*\.gif$/",$custom_name)) {
$errormessage[]="please give a senseful filename devoid of dumb characters, kthx? (nothing but alphanumerics, dash and underscore is allowed)";
}
if(file_exists("avatars/".$custom_name)) {
$errormessage[]="this filename already exists on the server";
}
// if everything is ok
if(!$errormessage)
$submitok=true;
}
if(!$submitok&&file_exists($userfile)){
unlink($userfile);
}
if($submitok) {
copy($userfile,"avatars/".$custom_name);
unlink($userfile);
/*
// reward the user
$query ="INSERT INTO avatars SET ";
$query.="avatar='".$userfile_name."',";
$query.="user=".$user["id"].",";
$query.="added=NOW()";
mysql_query($query);
*/
}
if($errormessage) { ?>
<table>
<?
for($i=0;$i<count($errormessage);$i++) {
print("<tr><td>error:</td><td><font color=\"#FF8888\">".$errormessage[$i]."</font><br></td></tr>\n");
}
?>
</table>
<? } ?>
<br>
<table width="50%"><tr><td valign="top">
<table bgcolor="#000000" cellspacing="1" cellpadding="0" border="0" width="100%">
<tr>
<td>
<table bgcolor="#000000" cellspacing="1" cellpadding="2" border="0" width="100%">
<tr bgcolor="#224488">
<th><b>some of the currently available avatars</b></th>
</tr>
<tr bgcolor="#446688">
<td>
<table width="100%">
<tr>
<?
$d = glob("avatars/*.gif");
$grid = 16;
$keyz = array_rand($d,$grid*$grid);
for ($i=0; $i<$grid*$grid; $i++) {
$entry = $d[$keyz[$i]];
print("<td align=\"center\"><img src=\"".$entry."\" width=\"16\" height=\"16\"></td>\n");
if(($i%$grid)==$grid-1) {
print("</tr><tr>\n");
}
}
/*
while($entry=$d->read()) {
$i++;
print("<td align=\"center\"><img src=\"avatars/".$entry."\" width=\"16\" height=\"16\"><br></td>\n");
if(!($i%8)) {
print("</tr><tr>\n");
}
}
$d->close();
while($i%8) {
$i++;
print("<td><br></td>\n");
}
*/
?>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<form action="avatar.php" enctype="multipart/form-data" method="post">
<table bgcolor="#000000" cellspacing="1" cellpadding="0" border="0" width="100%">
<tr>
<td>
<table bgcolor="#000000" cellspacing="1" cellpadding="2" border="0" width="100%">
<tr bgcolor="#224488">
<th><b>upload a new avatar</b></th>
</tr>
<tr bgcolor="#557799">
<td>
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td valign="bottom">
in order to upload a new avatar, make sure to follow those rules:<br>
<ul>
<li>it's a <b>.gif</b> file</li>
<li>it's <b>16</b> pixel width</li>
<li>it's <b>16</b> pixel height</li>
<li>it's <b>4</b>Kb max.</li>
<li>the background color is set to <b>transparent</b></li>
</ul>
if everything's ok, you can upload your file by using the <b>browse</b> button below.<br>
<br>
then your avatar will be available with the others.<br>
<br>
<input type="file" name="userfile">
</td>
<td>
<img src="gfx/example.gif" width="100" height="100"><br>
</td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#446688">
<td align="right" colspan="2">
<input type="image" src="gfx/submit.gif" border="0"><br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</td>
</tr></table>
<? require("include/bottom.php"); ?>