-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_file.php
97 lines (77 loc) · 3.26 KB
/
upload_file.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
<!DOCTYPE html>
<?php
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function generateRandomString1($length = 12) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$folder = generateRandomString();
$foder = "upload/".$folder."/";
mkdir('upload/'.$folder, 0777, true);
if ($_FILES["file"]["size"] < 2000000000000)
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
if (file_exists($foder . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
$foder . $_FILES["file"]["name"]);
$myfile = fopen($foder."index.html", "w") or die("Unable to open file!");
$foder = "upload/".$folder."/";
?>
<?php
$new = str_replace(' ', '%20', $_FILES["file"]["name"]);
$asdasdasd = $foder.$new;
$ucode = generateRandomString1();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
$date = date("Y/m/d");
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo '<div style="font-size:0.55em;color:#0e3c68;font-weight:bold;">download link: http://localhost/project/download.php?id='.$ucode.'</span></div>';
$download = "http://localhost/project/download.php?id='.$ucode";
$sql = "INSERT INTO onetimedownload (date, id, download)
VALUES ('$date', '$ucode', '$asdasdasd')";
?>
<script>
</script>
<?php
if ($conn->query($sql) === TRUE) {
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
}
}
else
{
echo "Invalid file";
}
?>