diff options
| -rw-r--r-- | database.sql | 13 | ||||
| -rw-r--r-- | sounds/upload.php | 13 |
2 files changed, 25 insertions, 1 deletions
diff --git a/database.sql b/database.sql new file mode 100644 index 0000000..4ca7639 --- /dev/null +++ b/database.sql @@ -0,0 +1,13 @@ +CREATE TABLE IF NOT EXISTS users ( + id BIGINT PRIMARY KEY AUTO_INCREMENT, + username TEXT NOT NULL, + token TEXT NOT NULL, + joined_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS sounds ( + id BIGINT PRIMARY KEY AUTO_INCREMENT, + code TEXT NOT NULL, + uploaded_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP, + uploaded_by BIGINT REFERENCES users(id) +);
\ No newline at end of file diff --git a/sounds/upload.php b/sounds/upload.php index 035775b..eecf9c5 100644 --- a/sounds/upload.php +++ b/sounds/upload.php @@ -3,6 +3,8 @@ include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/config.php'; include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/sounds.php'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $db = new PDO(DB_URL, DB_USER, DB_PASS); + try { if (!isset($_FILES['file'], $_POST['name'], $_POST['tos'])) { throw new RuntimeException("Not a valid request."); @@ -30,10 +32,19 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { mkdir(SOUND_DIRECTORY, 0777, true); } - compress_sound($file['tmp_name'], sprintf('%s/test.ogg', SOUND_DIRECTORY)); + $db->prepare('INSERT INTO sounds(code) VALUES (?)') + ->execute([$_POST['name']]); + + $id = $db->lastInsertId(); + + compress_sound($file['tmp_name'], sprintf('%s/%s.ogg', SOUND_DIRECTORY, $id)); exit("Uploaded!"); } catch (Exception $e) { + if (isset($id)) { + $db->prepare('DELETE FROM sounds WHERE id = ?') + ->execute([$id]); + } exit($e->getMessage()); } } |
