Ask ChatGPT for support then.
I have tried that for five days as well. It can not solve the problem. It says there is a problem with the way CF7 is handling uploads.
@takayukister
$size = getimagesize($_FILES[‘image’][‘tmp_name’]);
getimagesize() returns empty.
The file exists in $_FILES[‘image’][‘tmp_name’], but image metadata cannot be read from it during validation.
$_FILES:
(
[name] => test.jpg
[full_path] => test.jpg
[type] => image/jpeg
[tmp_name] => /Applications/XAMPP/xamppfiles/temp/phpr5jkh2
[error] => 0
[size] => 611211
)
I got it working with this code:
add_filter('wpcf7_validate_file*', 'validate_image_dimensions_cf7', 20, 2);
add_filter('wpcf7_validate_file', 'validate_image_dimensions_cf7', 20, 2);
function validate_image_dimensions_cf7($result, $tag) {
$name = $tag->name;
// Dit præcise felt-navn
if ($name !== 'catch-image') {
return $result;
}
error_log("CF7 Dimension Validation started for field: " . $name);
$submission = WPCF7_Submission::get_instance();
if (!$submission) {
error_log("No submission instance found");
return $result;
}
$uploaded_files = $submission->uploaded_files();
if (empty($uploaded_files[$name]) || empty($uploaded_files[$name][0])) {
error_log("No uploaded file in submission for " . $name);
$result->invalidate($tag, "Filen blev ikke modtaget korrekt.");
return $result;
}
$file_path = $uploaded_files[$name][0];
if (!file_exists($file_path)) {
error_log("File not found at path: " . $file_path);
$result->invalidate($tag, "Filen blev ikke modtaget korrekt på serveren.");
return $result;
}
error_log("File found at: " . $file_path);
$info = @getimagesize($file_path);
if ($info === false || empty($info[0]) || empty($info[1])) {
$result->invalidate($tag, "Filen er ikke et gyldigt billede.");
return $result;
}
$width = (int) $info[0];
$height = (int) $info[1];
error_log("Billede dimensioner: {$width}×{$height} px");
if ($width < 3000 || $height < 3000) {
$result->invalidate(
$tag,
sprintf("Billedet er for lille (%d×%d px). Minimumskrav: 3000×3000 pixels.", $width, $height)
);
error_log("Invalidation triggered - image too small");
} else {
error_log("Image passed validation");
}
return $result;
}