-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
103 lines (96 loc) · 4.86 KB
/
index.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
<?php
error_reporting(0);
include("settings.php");
# see ./assets/translations for available languages (USE IEFT language codes: https://en.wikipedia.org/wiki/IETF_language_tag#List_of_common_primary_language_subtags)
$availableLanguages = array("en", "de");
$choosenLanguage = in_array(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2), $availableLanguages) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en";
include("assets/translations/texts_" . $choosenLanguage . ".php");
$numberOfSuccessfullUploadedFiles = 0;
$collectedFilenames = "";
$simplifiedDomainname = trim(parse_url($yourDomain, PHP_URL_HOST));
// remove illegal file system characters https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
function sanitizeFilename($name): string {
$name = str_replace(array_merge(
array_map('chr', range(0, 31)),
array('<', '>', ':', '"', '/', '\\', '|', '?', '*', ' ', '-', '\'')
), '', $name);
$ext = pathinfo($name, PATHINFO_EXTENSION);
return mb_strcut(pathinfo($name, PATHINFO_FILENAME), 0, 200 - ($ext ? strlen($ext) + 1 : 0),
mb_detect_encoding($name)) . ($ext ? '.' . $ext : '');
}
if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
// Loop through $_FILES to treat all files
foreach ($_FILES['files']['name'] as $f => $filename) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Skip file on any error
}
if ($_FILES['files']['error'][$f] == 0) {
try {
$randomPrefix = bin2hex(random_bytes(10));
} catch (Exception $ignore) {
$randomPrefix = substr(hash('sha256', openssl_random_pseudo_bytes(20)), 10);
}
$sanitizedFilename = $randomPrefix . "_" . sanitizeFilename($filename);
if (move_uploaded_file($_FILES["files"]["tmp_name"][$f], $uploadDirectory . $sanitizedFilename)) {
$collectedFilenames = $collectedFilenames . "\r\n" . $sanitizedFilename . " <=> " . $yourDomain . "/" . $projectDirectory . $uploadDirectory . $sanitizedFilename;
$numberOfSuccessfullUploadedFiles++;
}
}
}
if ($numberOfSuccessfullUploadedFiles > 0) {
mb_internal_encoding('UTF-8');
$encoded_subject = mb_encode_mimeheader(textNewFileUpload($simplifiedDomainname, $numberOfSuccessfullUploadedFiles), 'UTF-8', 'B', "\r\n", strlen('Subject: '));
$header = 'From: ' . $addressToReportTo . "\r\n" . 'Reply-To: ' . $addressToReportTo . "\r\n" . 'X-Mailer: PHP/' . phpversion();
$message = textMailMessage($numberOfSuccessfullUploadedFiles, $_SERVER['REMOTE_ADDR'], $collectedFilenames);
mail($addressToReportTo, $encoded_subject, $message, $header);
}
}
echo "<!doctype html>
<html lang=\"$choosenLanguage\">";
?>
<head>
<meta charset="UTF-8"/>
<META NAME="ROBOTS" CONTENT="NOINDEX,NOFOLLOW">
<title><?php echo textTitle() . " | " . $simplifiedDomainname; ?></title>
<link rel="stylesheet" href="assets/style.css">
<link rel="apple-touch-icon" sizes="180x180" href="assets/favicon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="assets/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="assets/favicon/favicon-16x16.png">
<link rel="manifest" href="assets/favicon/site.webmanifest">
<link rel="mask-icon" href="assets/favicon/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
</head>
<body>
<div class="logo" style="text-align: center;" alt="">
<img src="assets/Circle-icons-speedometer.svg" width="150px" height="150px" alt="logo">
</div>
<div style="text-align: center;"><h1><?php echo $simplifiedDomainname ?></h1></div>
<div class="wrap">
<h1>
<?php
echo textTitle() . ":</h1>";
# show error messages if upload failed
if (isset($message)) {
foreach ($message as $msg) {
printf("<p class='status'>%s</p><br />\n", $msg);
}
}
# success message if upload has finisched
if ($numberOfSuccessfullUploadedFiles > 0) {
printf("<p class='status'>%d " . textSuccessfulUploaded() . "</p>\n", $numberOfSuccessfullUploadedFiles);
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple="multiple" accept="*">
<p><b><?php echo textUploadSubline(); ?></b></p>
<input type="submit" value="<?php echo textUploadButton(); ?>">
</form>
<p style="font-style: italic;"><?php echo textUploadBottomLine(); ?></p>
</div>
<div class="footer">
<a href="https://github.com/timluedtke/minimalistic-PHP-Upload" target="_blank">minimalistic-PHP-Upload v1.3.2<br/>
<img src="assets/GitHub_Logo.png" alt="logo github"></a>
</div>
</body>
</html>