-
Notifications
You must be signed in to change notification settings - Fork 3
/
image.php
95 lines (94 loc) · 3.01 KB
/
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
<?php
$stime=microtime(true);
if(file_exists("config.php")) {
require "config.php";
} else {
define("storage",dirname(__FILE__)."/storage/");
define("chatfile","chat.log");
define("linkchar1","&");
define("linkchar2","'says'");
};
if(!defined("storage")){
define("storage",dirname(__FILE__)."/storage/");
};
if(!defined("chatfile")){
define("chatfile","chat.log");
};
if(!defined("linkchar1")){
define("linkchar1","&");
};
if(!defined("linkchar2")){
define("linkchar2","'says'");
};
try{
date_default_timezone_set('PRC');
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('HTTP_X_FORWARDED')) {
$ip = getenv('HTTP_X_FORWARDED');
} elseif (getenv('HTTP_FORWARDED_FOR')) {
$ip = getenv('HTTP_FORWARDED_FOR');
} elseif (getenv('HTTP_FORWARDED')) {
$ip = getenv('HTTP_FORWARDED');
} elseif (getenv('REMOTE_ADDR')) {
$ip = getenv('REMOTE_ADDR');
} elseif (!empty($_SERVER['REMOTE_ADDR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
} else {
$ip = "Unknown";
};
if (empty($_POST['username'])){
$etime=microtime(true);
$totaltime=$etime-$stime;
echo "User Name empty.</br>Total time: ".$totaltime."s.";
exit;
};
if($_FILES["file"]["error"])
{
echo $_FILES["file"]["error"];
}
else
{
if(($_FILES["file"]["type"]=="image/png"||$_FILES["file"]["type"]=="image/jpeg")&&$_FILES["file"]["size"]<1048576)
{
$filename =storage."img/".time().".png";
$filename =iconv("gb2312","UTF-8",$filename);
if(file_exists($filename))
{
$etime=microtime(true);
$totaltime=$etime-$stime;
echo"File exist.</br>Total time: ".$totaltime."s.";
exit();
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],$filename);
}
}
else
{
$etime=microtime(true);
$totaltime=$etime-$stime;
echo"Unknown file type.</br>Total time: ".$totaltime."s.";
exit();
}
}
$un = $_POST['username'];
$time = date('H:i',time());
$timehidden = date('Y-m-d H:i:s',time());
if(file_exists(storage.''.chatfile)) {
$myfile = fopen(storage.''.chatfile, "a") or die("Unable to open file!");
fwrite($myfile,$ip . "+" . $timehidden . "" . linkchar1 . "[".$time."] [" . $un . "] " .linkchar2 . "" . "<img src=\"".str_replace(dirname(__FILE__), '', ".".$filename)."\" />" . "\r\n");
fclose($myfile);
} else {
file_put_contents(storage.''.chatfile, $ip . "+" . $timehidden . "" . linkchar1 . "[".$time."] [" . $un . "] " .linkchar2 . "" . "<img src=\"".str_replace(dirname(__FILE__), '', ".".$filename)."\" />" . "\r\n");
};
$etime=microtime(true);
$totaltime=$etime-$stime;
echo "Success.</br>Total time: ".$totaltime."s.<script>window.opener=null;window.close();</script>";
}catch(Exception $e){
echo $e->getMessage();
exit();
}