OJD: Add recent changes list
[eidogo-ojd.git] / php / save.php
blobc69df8ac360fc937ed62d7bd039d3cda33964e8b
1 <?php
3 function to_base($numstring, $frombase, $tobase) {
4 $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
5 $tostring = substr($chars, 0, $tobase);
7 $length = strlen($numstring);
8 $result = '';
9 for ($i = 0; $i < $length; $i++) {
10 $number[$i] = strpos($chars, $numstring{$i});
12 do {
13 $divide = 0;
14 $newlen = 0;
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;
24 $length = $newlen;
25 $result = $tostring{$divide} . $result;
27 while ($newlen != 0);
28 return $result;
30 $stamp = microtime(true) * (rand() / getrandmax()) * 100;
31 $id = to_base((string)$stamp, 10, 62);
33 $sgf = $_POST['sgf'];
34 if (get_magic_quotes_gpc()) $sgf = stripslashes($_POST['sgf']);
35 if (strlen($sgf) > 30000) {
36 // ~ 30 KB limit
37 exit;
39 file_put_contents("../sgf/saved/$id.sgf", $sgf);
41 echo $id;