3 function to_base($numstring, $frombase, $tobase) {
4 $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
5 $tostring = substr($chars, 0, $tobase);
7 $length = strlen($numstring);
9 for ($i = 0; $i < $length; $i++
) {
10 $number[$i] = strpos($chars, $numstring{$i});
15 for ($i = 0; $i < $length; $i++
) {
16 $divide = $divide * $frombase +
$number[$i];
17 if ($divide >= $tobase) {
18 $number[$newlen++
] = (int)($divide / $tobase);
19 $divide = $divide %
$tobase;
20 } elseif ($newlen > 0) {
21 $number[$newlen++
] = 0;
25 $result = $tostring{$divide} . $result;
30 $stamp = microtime(true) * (rand() / getrandmax()) * 100;
31 $id = to_base((string)$stamp, 10, 62);
34 if (get_magic_quotes_gpc()) $sgf = stripslashes($_POST['sgf']);
35 if (strlen($sgf) > 30000) {
39 file_put_contents("../sgf/saved/$id.sgf", $sgf);