summaryrefslogtreecommitdiff
path: root/public/emotes
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-19 17:27:12 +0500
committerilotterytea <iltsu@alright.party>2025-04-19 17:27:12 +0500
commit7a66de9852d4683a7b5cdcedb8e88cfdc73f4b56 (patch)
tree70437ad219721c0e74252ed51775142ca2f8b416 /public/emotes
parent9c2f42e423096bdf56b7f96e07221f6420b0e337 (diff)
feat: extract extension and mime from image
Diffstat (limited to 'public/emotes')
-rw-r--r--public/emotes/upload.php22
1 files changed, 18 insertions, 4 deletions
diff --git a/public/emotes/upload.php b/public/emotes/upload.php
index e68aea4..6d43daf 100644
--- a/public/emotes/upload.php
+++ b/public/emotes/upload.php
@@ -42,11 +42,25 @@ if ($code == "") {
exit;
}
+$image = $_FILES["file"];
+
+if (is_null(list($mime, $ext) = get_mime_and_ext($image["tmp_name"]))) {
+ http_response_code(400);
+ echo json_encode([
+ "status_code" => 400,
+ "message" => "Not a valid image",
+ "data" => null
+ ]);
+ exit;
+}
+
// creating a new emote record
$db = new SQLite3("../../database.db");
-$stmt = $db->prepare("INSERT INTO emotes(code) VALUES (:code)");
+$stmt = $db->prepare("INSERT INTO emotes(code, mime, ext) VALUES (:code, :mime, :ext)");
$stmt->bindValue(":code", $code);
+$stmt->bindValue(":mime", $mime);
+$stmt->bindValue(":ext", $ext);
$results = $stmt->execute();
$id = $db->lastInsertRowID();
@@ -68,8 +82,6 @@ if (!is_dir($path)) {
mkdir($path, 0777, true);
}
-$image = $_FILES["file"];
-
// resizing the image
// TODO: make it configurable later
@@ -103,7 +115,9 @@ if (isset($_SERVER["HTTP_ACCEPT"]) && $_SERVER["HTTP_ACCEPT"] == "application/js
"message" => null,
"data" => [
"id" => $id,
- "code" => $code
+ "code" => $code,
+ "ext" => $ext,
+ "mime" => $mime
]
]);
exit;