예제 #1
0
function performDelete()
{
    validateUser();
    withStatement("DELETE FROM DATA WHERE id=?", function ($statement) {
        $id = getParameter(PARAMETER_ID, PARAMETER_REQUIRED);
        $statement->bind_param("s", $id);
        executeStatement($statement);
    });
}
예제 #2
0
function newLogin()
{
    withStatement("INSERT INTO SESSION (SESSION_ID,CREATED) VALUES (?,NOW())", function ($statement) {
        $sessionId = generateSessionId();
        $statement->bind_param("s", $sessionId);
        executeStatement($statement);
        $baseUrl = getBaseUrl();
        $loginEmail = emailPrefixToAddress(LOGIN_EMAIL_PREFIX);
        sendEmail(emailPrefixToAddress(LOGIN_EMAIL_PREFIX), "Innlogging", "\n\nLogg inn via denne linken:\n{$baseUrl}/php/login.php?sessionId={$sessionId}");
        echo "{\"email\":\"{$loginEmail}\"}";
    });
}
예제 #3
0
    return $_FILES['file']['type'];
}
function getName()
{
    return $_FILES['file']['name'];
}
$performPost = function () {
    validateUser();
    $id = getParameter(PARAMETER_ID, PARAMETER_REQUIRED);
    $dataType = getParameter(PARAMETER_DATA_TYPE, PARAMETER_REQUIRED);
    $contentType = getContentType();
    $data = getData();
    $name = getName();
    $insert = withStatement("SELECT id FROM DATA WHERE id=?", function ($statement) use($id) {
        $statement->bind_param("s", $id);
        return countRows($statement) == 0;
    });
    if ($insert) {
        withStatement("INSERT INTO DATA(id,dataType,contentType,data, name) VALUES(?,?,?,?,?)", function ($statement) use($id, $dataType, $contentType, $data, $name) {
            $statement->bind_param("sssss", $id, $dataType, $contentType, $data, $name);
            executeStatement($statement);
        });
    } else {
        withStatement("UPDATE DATA SET data=?,dataType=?,contentType=?,name=? WHERE id=?", function ($statement) use($id, $dataType, $contentType, $data, $name) {
            $statement->bind_param("sssss", $data, $dataType, $contentType, $name, $id);
            executeStatement($statement);
        });
    }
};
validateUser();
handleRequest(array("POST" => $performPost));
<?php

include "util/all.php";
$performGet = function () {
    withStatement("SELECT name, contentType, data FROM DATA WHERE ID=?", function ($statement) {
        $id = getParameter(PARAMETER_ID, PARAMETER_REQUIRED);
        $statement->bind_param("s", $id);
        executeStatement($statement);
        $result = $statement->get_result();
        list($name, $type, $data) = $result->fetch_array();
        $name = $name ? $name : "file";
        if ($data) {
            header("Content-type: {$type}");
            header("Content-Disposition: attachment; filename=\"{$name}\"");
            echo $data;
        } else {
            setStatus(404, "Not Found");
        }
    });
};
handleRequest(array("GET" => $performGet));