You can do it by implementing your own custom validation filter.
I tried with this code, but it seems to stop the form from uploading.
add_filter('wpcf7_validate_file*', 'cf7_pre_validate_image_strict', 20, 2);
function cf7_pre_validate_image_strict($result, $tag) {
if ($tag->name !== 'catch_image') {
return $result;
}
if (empty($_FILES['catch_image']['tmp_name'])) {
$result->invalidate($tag, "No file uploaded.");
return $result;
}
$file = $_FILES['catch_image']['tmp_name'];
if (!is_uploaded_file($file)) {
$result->invalidate($tag, "Upload failed. Please try again.");
return $result;
}
// sikker læsning (vigtig: undgå getimagesize crash)
$info = @getimagesize($file);
if ($info === false || empty($info[0]) || empty($info[1])) {
$result->invalidate($tag, "Invalid image file.");
return $result;
}
$width = (int) $info[0];
$height = (int) $info[1];
if ($width < 4000 || $height < 3000) {
$result->invalidate(
$tag,
"Image too small. Minimum 4000x3000px required."
);
}
return $result;
}
Where can we see the form in question?
You can see the basic test form here:
https://specimenbaits.com/add-catch-report/
I have disabled my validation code.
This is the form field:
[file* catch_image filetypes:jpg|jpeg|heic limit:20mb]
Right now the form is set up to email and it works fine without the validation.
I will set it up to store the results and attachments in the database and send notification emails without attachment.