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 -
Upload a new emote
You can just upload, btw. Anything you want.
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);
}
if ($is_manual) {
$image_1x = $_FILES["file-1x"];
$image_2x = $_FILES["file-2x"];
$image_3x = $_FILES["file-3x"];
$file_1x = does_file_meet_requirements($image_1x["tmp_name"], $max_width / 4, $max_height / 4);
$file_2x = does_file_meet_requirements($image_2x["tmp_name"], $max_width / 2, $max_height / 2);
$file_3x = does_file_meet_requirements($image_3x["tmp_name"], $max_width, $max_height);
if (!$file_1x[0] || !$file_2x[0] || !$file_3x[0]) {
generate_alert("/emotes/upload.php", "Files don't meet requirements");
abort_upload($path, $db, $id);
exit;
}
if (
!move_uploaded_file($image_1x["tmp_name"], "$path/1x.$file_1x[1]") ||
!move_uploaded_file($image_2x["tmp_name"], "$path/2x.$file_2x[1]") ||
!move_uploaded_file($image_3x["tmp_name"], "$path/3x.$file_3x[1]")
) {
generate_alert("/emotes/upload.php", "Failed to move the uploaded files");
abort_upload($path, $db, $id);
exit;
}
} else {
$image = $_FILES["file"];
// resizing the image
if ($err = create_image_bundle($image["tmp_name"], $path, $max_width, $max_height)) {
generate_alert("/emotes/upload.php", "Error occurred while processing images ($err)", 500);
abort_upload($path, $db, $id);
exit;
}
if (EMOTE_STORE_ORIGINAL) {
$ext = get_file_extension($image["tmp_name"]) ?? "";
move_uploaded_file($image["tmp_name"], "$path/original.$ext");
}
}
if (ACCOUNT_LOG_ACTIONS && $uploaded_by != null) {
$db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)")
->execute([
$uploaded_by,
"EMOTE_CREATE",
json_encode([
"emote" => [
"id" => $id,
"code" => $code,
"visibility" => $visibility,
"uploaded_by" => $uploaded_by,
]
])
]);
}
$db = null;
if (CLIENT_REQUIRES_JSON) {
json_response([
"status_code" => 201,
"message" => null,
"data" => [
"id" => $id,
"code" => $code,
"uploaded_by" => $uploaded_by
]
], 201);
exit;
}
header("Location: /emotes?id=$id", true, 307);