Пример #1
0
function checkLogin()
{
    jsonStart();
    logAction('checkLogin', $_SESSION['user']);
    if (isset($_SESSION['userid'])) {
        jsonAdd("\"login\": \"true\",\"name\": \"{$_SESSION['name']}\"");
    } else {
        jsonAdd("\"login\": \"false\"");
    }
    echo jsonReturn('userLogin');
}
Пример #2
0
function uploadSmart()
{
    global $uploadDir;
    if (!file_exists($uploadDir . "stats_" . session_id() . ".txt")) {
        jsonStart();
        jsonAdd("\"percent\": 0, \"percentSec\": 0, \"speed\": \"0\", \"secondsLeft\": \"0\", \"done\": \"false\"");
        echo jsonReturn("bindings");
        exit;
    }
    $lines = file($uploadDir . "stats_" . session_id() . ".txt");
    jsonStart();
    $percent = round($lines[0] / 100, 3);
    $percentSec = round($lines[1] / 100, 4);
    $speed = filesize_format($lines[2]) . 's';
    $secondsLeft = secs_to_string(round($lines[3]));
    $size = filesize_format($lines[4]) . 's';
    if ($percent == 1) {
        // cleanup time
        if (isset($_SESSION['uploadPath'])) {
            $path = $_SESSION['uploadPath'];
            $userpath = getUserPath($path) . $path;
            $sessionid = session_id();
            $dh = opendir($uploadDir);
            while (($file = readdir($dh)) !== false) {
                $sessionlen = strlen(session_id());
                if (substr($file, 0, $sessionlen) == session_id()) {
                    $filename = substr($file, $sessionlen + 1);
                    $uploadfile = $filename;
                    $i = 1;
                    while (file_exists($userpath . '/' . $uploadfile)) {
                        $uploadfile = $i . '_' . $filename;
                        $i++;
                    }
                    if (file_exists("{$uploadDir}{$file}") && !rename("{$uploadDir}{$file}", "{$userpath}/{$uploadfile}")) {
                        echo "Error";
                    }
                }
            }
            closedir($dh);
            if (file_exists($uploadDir . "stats_" . session_id() . ".txt")) {
                unlink($uploadDir . "stats_" . session_id() . ".txt");
            }
            if (file_exists($uploadDir . "temp_" . session_id())) {
                unlink($uploadDir . "temp_" . session_id());
            }
        }
        $done = "true";
    } else {
        $done = "false";
    }
    jsonAdd("\"percent\": {$percent}, \"size\": \"{$size}\",\"percentSec\": {$percentSec}, \"speed\": \"{$speed}\", \"secondsLeft\": \"{$secondsLeft}\", \"done\": \"{$done}\"");
    echo jsonReturn("bindings");
}