-
Notifications
You must be signed in to change notification settings - Fork 64
/
upload.php
48 lines (43 loc) · 1.32 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
<?php
function to_base($numstring, $frombase, $tobase) {
$chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
$tostring = substr($chars, 0, $tobase);
$length = strlen($numstring);
$result = '';
for ($i = 0; $i < $length; $i++) {
$number[$i] = strpos($chars, $numstring{$i});
}
do {
$divide = 0;
$newlen = 0;
for ($i = 0; $i < $length; $i++) {
$divide = $divide * $frombase + $number[$i];
if ($divide >= $tobase) {
$number[$newlen++] = (int)($divide / $tobase);
$divide = $divide % $tobase;
} elseif ($newlen > 0) {
$number[$newlen++] = 0;
}
}
$length = $newlen;
$result = $tostring{$divide} . $result;
}
while ($newlen != 0);
return $result;
}
$stamp = microtime(true) * (rand() / getrandmax()) * 100;
$id = to_base((string)$stamp, 10, 62);
if ($_POST['type'] == "paste") {
$sgf = $_POST['sgf'];
if (get_magic_quotes_gpc()) $sgf = stripslashes($_POST['sgf']);
} elseif ($_POST['type'] == "file") {
$sgf = file_get_contents($_FILES['sgf_file']['tmp_name']);
@unlink($_FILES['sgf_file']['tmp_name']);
}
if (strlen($_POST['sgf'] > 30000)) {
exit;
}
file_put_contents("../sgf/saved/$id.sgf", $sgf);
header("location: /#$id");
echo $id;
?>