-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostData.php
More file actions
118 lines (98 loc) · 3.38 KB
/
Copy pathpostData.php
File metadata and controls
118 lines (98 loc) · 3.38 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
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
<?php
//################################################
//########### STRING UPLOAD ######################
//################################################
$params = "No params";
if (isset($_POST["postparam"]))
{
$params = "Params : ";
foreach ($_POST["postparam"] as $_item)
{
$params .= htmlspecialchars($_item).", ";
}
}
//################################################
//########### FILE UPLOAD ########################
//################################################
$FilesUploaded = "No file received";
if(isset($_FILES['file']))
{
$upload_dir = 'upload/';
$file = basename($_FILES['file']['name']);
$max_size = 500000;
$file_size = filesize($_FILES['file']['tmp_name']);
$allowed_extensions = array('.txt');
$extension = strrchr($_FILES['file']['name'], '.');
if ($file != "") //could occur if no file is uploaded from HTML form
{
if(!in_array($extension, $allowed_extensions)) //Check extension
$FilesUploaded = 'Only extension txt, jpg, jpeg, txt, csv and png are allowed (Extension used ' .$extension . ').' ;
if($file_size>$max_size)
$FilesUploaded = 'File too big';
if($FilesUploaded == "No file received") //If no error, start upload
{
//format file name
$file = strtr($file,
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$file = preg_replace('/([^.a-z0-9]+)/i', '-', $file);
if(move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir . date('m-d-Y_His')."_".$file)) //If true is returned -> it worked
{
$FilesUploaded = " File uploaded :". $file." (Click <a href='upload/".$_SERVER['REMOTE_ADDR']."_".$file."'>here</a> to access the file)";
echo "File Uploaded successfully";
}
else //if false, upload has failed
echo "File Upload failed (eWON return code : POSTERROR)";
}
else
echo $FilesUploaded." (eWON return code : POSTERROR)";
}
}
//################################################
//########### LOG RESULT #########################
//################################################
//YOU COMMENTED OUT THIS TO STOP THE BOT FROM DELETING EVERYTHING SO FREAKING OFTEN!
//remove uploaded file and log file if filesize > 3 kb
//if (file_exists('postresults.txt'))
//{
// if (filesize('postresults.txt') > 3000)
// clearAll();
//}
//log result in file
$fp = fopen('postresults.txt', 'a');
fwrite($fp, date('Y-m-d H:m:s')." [".$_SERVER['REMOTE_ADDR']."]"." : ".$params." ".$FilesUploaded."\r\n");
fclose($fp);
//remove uploaded file and log file on demand
if (isset($_POST["clearlist"]))
clearAll();
//redirect to main page
echo "<head><SCRIPT LANGUAGE='JavaScript'>document.location.href='index.php'</SCRIPT></head>";
function clearAll()
{
try
{
deleteDir('upload');
mkdir('upload');
unlink('postresults.txt');
}
catch(Exception $e)
{}
}
function deleteDir($dirPath) {
if (! is_dir($dirPath)) {
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
self::deleteDir($file);
} else {
unlink($file);
}
}
rmdir($dirPath);
}
?>