-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathupload.php
66 lines (46 loc) · 1.59 KB
/
upload.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
<?php
define('RAW_IMAGE', false);
define('RAW_IMAGE_LINK', true);
define('IMAGE_EXTENSION', false);
define('TWITTER_CARDS', false);
define('IMAGESERVE_DIR', '');
define('TWITTER_HANDLE', '@PubCc');
define('APP_NAME', 'ReflectiveLoader.exe');
define('PASSKEY', 'zPQ6uinI0usDn3YfiIftLPZYeqT1Tw');
$allowedTypes = array('image/png', 'image/jpeg');//, 'image/gif', 'video/webm');
if ( ! isset($_POST['secret']) || $_POST['secret'] !== PASSKEY) {
die('error,e-401');
}
if ( ! (filesize($_FILES['sharex']['tmp_name']) > 0 && in_array($_FILES['sharex']['type'], $allowedTypes))) {
die('error,e-415');
}
if ($_FILES['sharex']['error'] > 0) {
die('error,e-500');
}
$dir = __DIR__ . '/images/';
saveImage($_FILES['sharex']['type'], $_FILES['sharex']['tmp_name']);
function generateNewHash($type)
{
$an = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$str = '';
for ($i = 0; $i < 5; $i++) {
$str .= substr($an, rand(0, strlen($an) - 1), 1);
}
if ( ! file_exists(__DIR__ . "/images/$str.$type")) {
return $str;
} else {
return generateNewHash($type);
}
}
function saveImage($mimeType, $tempName)
{
global $dir;
$mimeTypeArray = explode('/', $mimeType);
$type = $mimeTypeArray[1];
$hash = generateNewHash($type);
$dir3 = "https://".$_SERVER['SERVER_NAME']."/";
if (move_uploaded_file($tempName, $dir . "$hash.$type")) {
die('' . (RAW_IMAGE_LINK ? $dir3 . "$hash.$type" : ($type == 'png' ? '' : substr($type, 0, 1) . '/') . "$hash" . (IMAGE_EXTENSION ? ".$type" : '')));
}
die('error,e-500x');
}