This repository has been archived by the owner on Oct 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
243 lines (204 loc) · 9.4 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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
/*
* Import the config and uploads json files.
*/
$config = json_decode(file_get_contents("protected/config.json"), true);
$uploads = json_decode(file_get_contents("protected/uploads.json"), true);
/*
* Getting the values from the config into php variables.
*/
$cfgDirectory = $config["directory"];
$cfgDomain = $config["domain"];
/*
* Functions that are needed.
*
* human_filesize returns a human readable filesize, found somewhere on stackoverflow.
*/
function human_filesize($bytes, $decimals) {
$size = array('B','KB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f ", $bytes / pow(1024, $factor)) . @$size[$factor];
}
/*
* Default variables, nothing special.
*/
$file = $_GET["f"];
$extension = str_replace(".", "", strrchr($file, '.'));
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off" ? "https" : "http" . "://";
$stylesheet = __DIR__ . "assets/style.css";
if (isset($file)) {
$fileSize = human_filesize(filesize("uploads/$file"), 2);
}
/*
* Getting the values from the upload log into php variables.
* Read the upload.php file or documentation for more information about the upTimes.
*/
$upPath = $uploads[$file]["path"];
$upTime = $uploads[$file]["time"]["time"];
$upTimeDayNum = $uploads[$file]["time"]["dayNum"];
$upTimeDayName = $uploads[$file]["time"]["dayName"];
$upTimeDayNameFull = $uploads[$file]["time"]["dayNameFull"];
$upTimeMonthNum = $uploads[$file]["time"]["monthNum"];
$upTimeMonthName = $uploads[$file]["time"]["monthName"];
$upTimeMonthNameFull = $uploads[$file]["time"]["monthNameFull"];
$upTimeYear = $uploads[$file]["time"]["year"];
$upTimeYearShort = $uploads[$file]["time"]["yearShort"];
$uploadTime = "$upTimeDayNum $upTimeMonthNameFull $upTimeYear - $upTime";
/*
* Loading embed data from the config file.
*/
$embedEnabled = $config["embed"]["enabled"];
$embedAuthor = $config["embed"]["author"];
$embedTitle = $config["embed"]["title"];
$embedDescription = $config["embed"]["description"];
$embedColour = $config["embed"]["colour"];
/*
* Add placeholders by replacing strings with what is needed.
*/
$embedTitle = str_replace("{domain}", $cfgDomain, $embedTitle);
$embedTitle = str_replace("{filesize}", $fileSize, $embedTitle);
$embedTitle = str_replace("{filename}", $file, $embedTitle);
$embedTitle = str_replace("{uploaddate}", $uploadTime, $embedTitle);
$embedDescription = str_replace("{domain}", $cfgDomain, $embedDescription);
$embedDescription = str_replace("{filesize}", $fileSize, $embedDescription);
$embedDescription = str_replace("{filename}", $file, $embedDescription);
$embedDescription = str_replace("{uploaddate}", $uploadTime, $embedDescription);
$embedAuthor = str_replace("{domain}", $cfgDomain, $embedAuthor);
$embedAuthor = str_replace("{filesize}", $fileSize, $embedAuthor);
$embedAuthor = str_replace("{filename}", $file, $embedAuthor);
$embedAuthor = str_replace("{uploaddate}", $uploadTime, $embedAuthor);
/*
* Make an array for all extension types used in if statements in
* our HTML code to check what to display for the type of file uploaded.
*/
$imageExtensions = array("png", "jpg", "jpeg", "gif");
$videoExtensions = array("mp4", "webm", "mov");
$audioExtensions = array("mp3");
$otherExtensions = array("exe");
?>
<!--
The HTML/webpage.
Were we display the image with html.
-->
<html>
<head>
<?php
if (isset($file)) {
echo "<title>$file</title>";
if ($embedEnabled == true) {
$fileurl = $protocol . $cfgDomain . $cfgDirectory . "uploads/$file";
echo "<meta name='og:site_name' content='$embedAuthor'>";
foreach ($imageExtensions as $ext) {
if ($extension == $ext) {
echo "
<meta name='twitter:card' content='summary_large_image'>
<meta name='twitter:title' content='$embedTitle'>
<meta name='twitter:image' content='$fileurl'>
";
}
}
foreach ($videoExtensions as $ext) {
if ($extension == $ext) {
echo "
<meta name='twitter:card' content='player'>
<meta name='twitter:title' content='$embedTitle'>
<meta name='twitter:image' content='$fileurl'>
<meta name='twitter:player:width' content='1280'>
<meta name='twitter:player:height' content='720'>
";
}
}
foreach ($audioExtensions as $ext) {
if ($extension == $ext) {
echo "
<meta name='twitter:card' content='summary_large_image'>
<meta name='twitter:title' content='$embedTitle'>
";
}
}
foreach ($otherExtensions as $ext) {
if ($extension == $ext) {
echo "
<meta name='twitter:card' content='summary_large_image'>
<meta name='twitter:title' content='$embedTitle'>
";
}
}
echo "
<meta name='theme-color' content='$embedColour'>
<meta name='twitter:description' content='$embedDescription'>
";
}
} else {
echo "<title>$cfgDomain</title>";
}
?>
<link rel="stylesheet" href="<?php echo $stylesheet; ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<?php
if (isset($file)) {
foreach (scandir("uploads/") as $upload) {
if ($file == $upload) {
echo "
<center>
<div class='card'>
<div class='card-body'>
<h1 style='padding-bottom: 0; margin-bottom: 0;'>$file ($fileSize)</h1>
<p style='padding-top: 2px; margin-top: 2px; padding-bottom: 15px; margin-bottom: 15px;'>Uploaded at $uploadTime</p>
";
foreach ($imageExtensions as $ext) {
if ($extension == $ext) {
echo "
<img src='$upPath'></img>
";
}
}
foreach ($videoExtensions as $ext) {
if ($extension == $ext) {
echo "
<video controls>
<source src='$upPath'>
</video>
";
}
}
foreach ($audioExtensions as $ext) {
if ($extension == $ext) {
echo "
<audio controls>
<source src='$upPath'>
</audio>
";
}
}
foreach ($otherExtensions as $ext) {
if ($extension == $ext) {
echo "
<button>
<a href='$upPath' download>
Download
</a>
</button>
";
}
}
echo "
</div>
</div>
</center>
";
}
}
} else {
echo "
<center>
<h1 style='padding-bottom: 10; margin-bottom: 10; transform: scale(2);'>$cfgDomain</h1>
<p style='padding-top: 0; margin-top: 0; transform: scale(2);' class='light' >Hosted by <a href='https://github.com/ilyBenny/php-uploader'>PHP Uploader</a>.</p>
</center>
";
}
?>
</body>
</html>