aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/PicoFarad/Request.php
blob: 46c82bca9919ec62b5240befc8f1e2d5c9fdcd38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php

namespace PicoFarad\Request;


function param($name, $default_value = null)
{
    return isset($_GET[$name]) ? $_GET[$name] : $default_value;
}


function int_param($name, $default_value = 0)
{
    return isset($_GET[$name]) && ctype_digit($_GET[$name]) ? (int) $_GET[$name] : $default_value;
}


function value($name)
{
    $values = values();
    return isset($values[$name]) ? $values[$name] : null;
}


function values()
{
    if (! empty($_POST)) {

        return $_POST;
    }

    $result = json_decode(body(), true);

    if ($result) {
        return $result;
    }

    return array();
}


function body()
{
    return file_get_contents('php://input');
}


function file_content($field)
{
    if (isset($_FILES[$field])) {
        return file_get_contents($_FILES[$field]['tmp_name']);
    }

    return '';
}


function file_info($field)
{
    if (isset($_FILES[$field])) {
        return array(
            'name' => $_FILES[$field]['name'],
            'mimetype' => $_FILES[$field]['type'],
            'size' => $_FILES[$field]['size'],
        );
    }

    return false;
}


function file_move($field, $destination)
{
    if (isset($_FILES[$field]) && ! file_exists($destination)) {
        @mkdir(dirname($destination), 0777, true);
        move_uploaded_file($_FILES[$field]['tmp_name'], $destination);
    }
}