summaryrefslogtreecommitdiff
path: root/sounds
diff options
context:
space:
mode:
Diffstat (limited to 'sounds')
-rw-r--r--sounds/upload.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/sounds/upload.php b/sounds/upload.php
new file mode 100644
index 0000000..035775b
--- /dev/null
+++ b/sounds/upload.php
@@ -0,0 +1,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> \ No newline at end of file