summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-05-07 14:43:37 +0500
committerilotterytea <iltsu@alright.party>2025-05-07 14:43:37 +0500
commit71937e5897c3dea1c418e4ebbd5ebd4c9f762b89 (patch)
treee88e6398dd9bf6e94653f9d552698d8e3d62ab07
parentd857bf78c0f8639eae9e21ffe4e04ee68e94d04b (diff)
feat: additional checks for pfp & banner upload in /account
-rw-r--r--public/account/index.php56
1 files changed, 38 insertions, 18 deletions
diff --git a/public/account/index.php b/public/account/index.php
index 5455727..80af380 100644
--- a/public/account/index.php
+++ b/public/account/index.php
@@ -36,28 +36,48 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
}
}
- if (isset($_FILES["pfp"])) {
+ if (isset($_FILES["pfp"]) && !empty($_FILES["pfp"]["tmp_name"])) {
$pfp = $_FILES["pfp"];
- resize_image(
- $pfp["tmp_name"],
- "../static/userdata/avatars/" . $_SESSION["user_id"],
- ACCOUNT_PFP_MAX_SIZE[0],
- ACCOUNT_PFP_MAX_SIZE[1],
- false,
- true
- );
+
+ if (!is_dir("../static/userdata/avatars")) {
+ mkdir("../static/userdata/avatars", 0777, true);
+ }
+
+ if (
+ $err = resize_image(
+ $pfp["tmp_name"],
+ $_SERVER["DOCUMENT_ROOT"] . "/static/userdata/avatars/" . $_SESSION["user_id"],
+ ACCOUNT_PFP_MAX_SIZE[0],
+ ACCOUNT_PFP_MAX_SIZE[1],
+ false,
+ true
+ )
+ ) {
+ generate_alert("/account", sprintf("Error occurred while processing the profile picture (%d)", $err));
+ exit;
+ }
}
- if (isset($_FILES["banner"])) {
+ if (isset($_FILES["banner"]) && !empty($_FILES["banner"]["tmp_name"])) {
$banner = $_FILES["banner"];
- resize_image(
- $banner["tmp_name"],
- "../static/userdata/banners/" . $_SESSION["user_id"],
- ACCOUNT_BANNER_MAX_SIZE[0],
- ACCOUNT_BANNER_MAX_SIZE[1],
- false,
- true
- );
+
+ if (!is_dir("../static/userdata/banners")) {
+ mkdir("../static/userdata/banners", 0777, true);
+ }
+
+ if (
+ $err = resize_image(
+ $banner["tmp_name"],
+ $_SERVER["DOCUMENT_ROOT"] . "/static/userdata/banners/" . $_SESSION["user_id"],
+ ACCOUNT_BANNER_MAX_SIZE[0],
+ ACCOUNT_BANNER_MAX_SIZE[1],
+ false,
+ true
+ )
+ ) {
+ generate_alert("/account", sprintf("Error occurred while processing the profile banner (%d)", $err));
+ exit;
+ }
}
$db = null;