Limit each image to 1 MB.

UPLOAD_MAX_MB changes the limit, and UPLOAD_MAX_MB=none removes it.
This commit is contained in:
tim
2026-09-26 15:27:51 +02:00
parent c4fcef21aa
commit 504d363642
5 changed files with 86 additions and 5 deletions
+9 -1
View File
@@ -206,10 +206,18 @@ function validate_data() {
$validate['story'] = "You've tried to remove an image without replacing it with text.";
}
$upload_max = upload_max_bytes();
$too_large = htmlspecialchars((string)($_FILES['upload']['name'] ?? '')) .
($upload_max === NULL ? ' is larger than the server accepts.' : ' is larger than '.upload_max_mb().' MB.') .
' Please choose a smaller image.';
// 0 == no error; 4 == no file; all others are errors.
if ($upload_error > 0 &&
if ($upload_error === UPLOAD_ERR_INI_SIZE || $upload_error === UPLOAD_ERR_FORM_SIZE) {
$validate['upload'] = $too_large;
} else if ($upload_error > 0 &&
$upload_error !== 4) {
$validate['upload'] = 'There was an error uploading the file ('.$upload_error.')';
} else if ($upload_tmp && $upload_max !== NULL && (int)@filesize($upload_tmp) > $upload_max) {
$validate['upload'] = $too_large;
} else if ($upload_tmp) {
$upload = getimagesize($upload_tmp);
if (!$upload)