Skip to content

Commit 5e0fb54

Browse files
committed
Improve check for uploaded files
1 parent 920b5a1 commit 5e0fb54

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes for Snaptcha
22

3+
## 5.1.1 - 2025-06-23
4+
5+
- Improved the check for uploaded files.
6+
37
## 5.1.0 - 2025-06-23
48

59
- Added an error message that is displayed if Snaptcha identifies a submission as spam when a file is uploaded, in which case the user must go back and resubmit their data ([#32](https://github.com/putyourlightson/craft-snaptcha/issues/32)).

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "putyourlightson/craft-snaptcha",
33
"description": "Automatically validates forms and prevents spam bots from submitting to your site.",
4-
"version": "5.1.0",
4+
"version": "5.1.1",
55
"type": "craft-plugin",
66
"homepage": "https://putyourlightson.com/plugins/snaptcha",
77
"license": "proprietary",

src/services/SnaptchaService.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,18 @@ public function getPostedValues(): array
9797
*/
9898
public function hasFileUpload(): bool
9999
{
100-
return !empty($_FILES) && $_FILES['file']['error'] === UPLOAD_ERR_OK;
100+
foreach ($_FILES as $file) {
101+
$error = $file['error'] ?? null;
102+
if (is_array($error)) {
103+
if (in_array(UPLOAD_ERR_OK, $error, true)) {
104+
return true;
105+
}
106+
} elseif ($error === UPLOAD_ERR_OK) {
107+
return true;
108+
}
109+
}
110+
111+
return false;
101112
}
102113

103114
/**
@@ -346,7 +357,7 @@ private function getNormalizedArray(array|string $values): array
346357
$value = $value[0];
347358
}
348359

349-
$values[$key] = trim($value, " \/");
360+
$values[$key] = trim($value, ' \/');
350361
}
351362
} else {
352363
$values = [];

0 commit comments

Comments
 (0)