summaryrefslogtreecommitdiff
path: root/sounds/upload.php
blob: 035775b4f263e215e2d99e45934ae217a51dd611 (plain)
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
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/config.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/sounds.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    try {
        if (!isset($_FILES['file'], $_POST['name'], $_POST['tos'])) {
            throw new RuntimeException("Not a valid request.");
        }

        $file = $_FILES['file'];

        if (!isset($file['error']) || is_array($file['error'])) {
            throw new RuntimeException('Invalid file.');
        }

        switch ($file['error']) {
            case UPLOAD_ERR_OK:
                break;
            case UPLOAD_ERR_NO_FILE:
                throw new RuntimeException("No file sent.");
            case UPLOAD_ERR_INI_SIZE:
            case UPLOAD_ERR_FORM_SIZE:
                throw new RuntimeException("Exceeded filesize limit.");
            default:
                throw new RuntimeException("Unknown errors.");
        }

        if (!is_dir(SOUND_DIRECTORY)) {
            mkdir(SOUND_DIRECTORY, 0777, true);
        }

        compress_sound($file['tmp_name'], sprintf('%s/test.ogg', SOUND_DIRECTORY));

        exit("Uploaded!");
    } catch (Exception $e) {
        exit($e->getMessage());
    }
}
?>
<!DOCTYPE html>
<html>

<head>
    <title>Sounds - tinyemotes</title>
    <link rel="stylesheet" href="/static/style.css">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
</head>

<body>
    <form action="/sounds/upload.php" method="post" enctype="multipart/form-data">
        <div class="column gap-8">
            <label for="file"><b>Sound<span class="red">*</span></b></label>
            <input type="file" name="file" id="file" required>
        </div>
        <div class="column gap-8">
            <label for="name"><b>Sound name<span class="red">*</span></b></label>
            <input type="text" name="name" id="name" required>
        </div>

        <div class="row gap-8">
            <label for="tos">Do you accept <a href="/tos.php">the rules</a>?<span class="red">*</span></label>
            <input type="checkbox" name="tos" id="tos" value="1">
        </div>

        <button type="submit">Upload</button>
    </form>
</body>

</html>