Exemple #1
0
 function finalizeUpload($token, $total_chunks, $prev_uploaded)
 {
     $prev_token = $_SESSION["upload_token"];
     if ($token != $prev_token) {
         $ret["success"] = false;
         $ret["code"] = "INVALID_TOKEN";
         return $ret;
     }
     if ($total_chunks != $_SESSION["uploaded_chunks"] + 1) {
         $ret["success"] = false;
         $ret["code"] = "INVALID_CHUNK_INDEX";
         return $ret;
     }
     if ($prev_uploaded != $_SESSION["uploaded_bytes"]) {
         $ret["success"] = false;
         $ret["code"] = "INVALID_PREV_UPLOADED";
         return $ret;
     }
     //
     unset($_SESSION["upload_token"]);
     unset($_SESSION["uploaded_bytes"]);
     unset($_SESSION["uploaded_chunks"]);
     //
     //
     $dbh = dbconnect();
     $user_id = $_SESSION["user_id"];
     $query = "INSERT INTO `images`(`owner_id`, `quadrant`) VALUES ({$user_id}, 0)";
     $count = $dbh->exec($query);
     $insert_id = $dbh->lastInsertId();
     NetDebug::trace("tpeof insert_id: " . gettype($insert_id));
     NetDebug::trace("insert_id: {$insert_id}");
     NetDebug::trace("insert_id*2: " . $insert_id * 2);
     $id64 = Id64::encode($insert_id);
     NetDebug::trace("id64: {$id64}");
     $now = time();
     $ip = ip2long($_SERVER['REMOTE_ADDR']);
     //
     $query = "INSERT INTO `image_uploads` (`upload_time` ,`image_id` ,`user_id` ,`user_ip`)\r\n                VALUES ('{$now}' , '{$insert_id}', {$user_id}, '{$ip}')";
     NetDebug::trace("query: {$query}");
     $count = $dbh->exec($query);
     NetDebug::trace("count: {$count}");
     //
     $tempFile_name = IMG_ROOT . "tmp/{$token}.tmp";
     $temp_file = fopen($tempFile_name, "r");
     do {
         $size_byte = fread($temp_file, 1);
         $size = ord($size_byte);
         $length_str = fread($temp_file, 4);
         //NetDebug::trace("length_str: $length_str");
         $length = ord($length_str[0]) << 24 | ord($length_str[1]) << 16 | ord($length_str[2]) << 8 | ord($length_str[3]);
         NetDebug::trace("length: {$length}");
         $data = fread($temp_file, $length);
         //
         $size_hex = dechex($size);
         $writeFolder_name = IMG_ROOT . "{$size_hex}/{$id64['0']}/{$id64['1']}";
         //$writeFolder_name = IMG_ROOT . "$size_hex";
         if (!file_exists($writeFolder_name)) {
             mkdir($writeFolder_name, 0775, true);
         }
         $writeFile_name = "{$writeFolder_name}/{$id64}.jpg";
         $writeFile = fopen($writeFile_name, 'w');
         fwrite($writeFile, $data);
         fclose($writeFile);
     } while (ftell($temp_file) < filesize($tempFile_name));
     fclose($temp_file);
     unlink($tempFile_name);
     //$file_name = "../upload/img/" . $token . ".jpg";
     //rename($tempFile_name, $file_name);
     //
     $ret["success"] = true;
     $ret["id"] = $id64;
     return $ret;
 }
Exemple #2
0
<?php

include "../etc/id64.php";
for ($i = 10; $i < 1000; $i++) {
    echo "<br>";
    $num = rand(0, pow(2, 31));
    $b32 = Id64::encode($num);
    $num2 = Id64::decode($b32);
    echo "{$num}  {$b32}  {$num2} ";
    echo $num == $num2 ? "v" : "x";
}