From 10cde47798f2a7b10a84a22f53aeddab1ceea720 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 20 Apr 2025 12:30:40 +0500 Subject: feat: upload page --- public/emotes/upload.php | 156 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 148 insertions(+), 8 deletions(-) (limited to 'public/emotes/upload.php') diff --git a/public/emotes/upload.php b/public/emotes/upload.php index 6d43daf..b0a3b71 100644 --- a/public/emotes/upload.php +++ b/public/emotes/upload.php @@ -1,4 +1,7 @@ prepare("DELETE FROM emotes WHERE id = :id"); @@ -15,8 +18,12 @@ function abort_upload(string $path, SQLite3 $db, string $id, string $response_te include "../../src/utils.php"; include "../../src/images.php"; +// TODO: make it configurable later +$max_width = max(128, 1); +$max_height = max(128, 1); + if ($_SERVER['REQUEST_METHOD'] != "POST") { - echo 'imagine there is a page'; + echo_upload_page(); exit; } @@ -57,10 +64,13 @@ if (is_null(list($mime, $ext) = get_mime_and_ext($image["tmp_name"]))) { // creating a new emote record $db = new SQLite3("../../database.db"); -$stmt = $db->prepare("INSERT INTO emotes(code, mime, ext) VALUES (:code, :mime, :ext)"); +$uploaded_by = $_SESSION["user_id"] ?? null; + +$stmt = $db->prepare("INSERT INTO emotes(code, mime, ext, uploaded_by) VALUES (:code, :mime, :ext, :uploaded_by)"); $stmt->bindValue(":code", $code); $stmt->bindValue(":mime", $mime); $stmt->bindValue(":ext", $ext); +$stmt->bindValue(":uploaded_by", $uploaded_by); $results = $stmt->execute(); $id = $db->lastInsertRowID(); @@ -84,10 +94,6 @@ if (!is_dir($path)) { // resizing the image -// TODO: make it configurable later -$max_width = max(128, 1); -$max_height = max(128, 1); - // 3x image $resized_image = resize_image($image["tmp_name"], "$path/3x", $max_width, $max_height); if ($resized_image) { @@ -117,10 +123,144 @@ if (isset($_SERVER["HTTP_ACCEPT"]) && $_SERVER["HTTP_ACCEPT"] == "application/js "id" => $id, "code" => $code, "ext" => $ext, - "mime" => $mime + "mime" => $mime, + "uploaded_by" => $uploaded_by ] ]); exit; } -header("Location: /emotes/$id", true, 307); \ No newline at end of file +header("Location: /emotes/$id", true, 307); + +function echo_upload_page() +{ + include "../../src/partials.php"; + + echo '' ?> + + + + Upload an emote at alright.party + + + + +
+
+ + +
+
+ +
+
+

Emote name

+ +

Image

+ + +
+ +
+ + +
+ + + +
+
+
+ + +
+
+
+ + + + + + +