prepare("DELETE FROM emotes WHERE id = ?"); $stmt->execute([$id]); $db = null; array_map("unlink", glob("$path/*.*")); rmdir($path); } include "../../src/utils.php"; include "../../src/images.php"; $max_width = EMOTE_MAX_SIZE[0]; $max_height = EMOTE_MAX_SIZE[1]; if ($_SERVER['REQUEST_METHOD'] != "POST") { include "../../src/partials.php"; echo '' ?> Upload an emote - <?php echo INSTANCE_NAME ?>

Emote name

Image


test

400, "message" => "No file set", "data" => null ]); exit; } $code = str_safe($_POST["code"] ?? "", EMOTE_NAME_MAX_LENGTH); if ($code == "" || !preg_match(EMOTE_NAME_REGEX, $code)) { http_response_code(400); echo json_encode([ "status_code" => 400, "message" => "Invalid code", "data" => null ]); exit; } $image = $_FILES["file"]; $notes = str_safe($_POST["notes"] ?? "", EMOTE_COMMENT_MAX_LENGTH); if (empty($notes)) { $notes = null; } $visibility = clamp(intval($_POST["visibility"], EMOTE_VISIBILITY_DEFAULT), 0, 2); if (MOD_EMOTES_APPROVE && $visibility == 1 && EMOTE_VISIBILITY_DEFAULT != 1) { $visibility = 2; } // creating a new emote record $db = new PDO(DB_URL, DB_USER, DB_PASS); $id = bin2hex(random_bytes(16)); $stmt = $db->prepare("INSERT INTO emotes(id, code, notes, uploaded_by, visibility) VALUES (?, ?, ?, ?, ?)"); $stmt->execute([$id, $code, $notes, $uploaded_by, $visibility]); $path = "../static/userdata/emotes/$id"; if (!is_dir($path)) { mkdir($path, 0777, true); } // resizing the image if ($err = resize_image($image["tmp_name"], "$path/3x", $max_width, $max_height)) { error_log("Error processing image: $err"); generate_alert("/emotes/upload.php", "Error occurred while processing the image ($err)", 500); abort_upload($path, $db, $id); exit; } if ($err = resize_image($image["tmp_name"], "$path/2x", $max_width / 2, $max_height / 2)) { error_log("Error processing image: $err"); generate_alert("/emotes/upload.php", "Error occurred while processing the image ($err)", 500); abort_upload($path, $db, $id); exit; } if ($err = resize_image($image["tmp_name"], "$path/1x", $max_width / 4, $max_height / 4)) { error_log("Error processing image: $err"); generate_alert("/emotes/upload.php", "Error occurred while processing the image ($err)", 500); abort_upload($path, $db, $id); exit; } $db = null; if (CLIENT_REQUIRES_JSON) { http_response_code(201); echo json_encode([ "status_code" => 201, "message" => null, "data" => [ "id" => $id, "code" => $code, "ext" => $ext, "mime" => $mime, "uploaded_by" => $uploaded_by ] ]); exit; } header("Location: /emotes?id=$id", true, 307);