1

I have a custom form in my WordPress web using Contact Form 7 like this:

<label> Tu correo electrónico (requerido)
    [email* your-email default:user_email] </label>

[file* archivo limit:5mb filetypes:png|jpg|jpeg]

[submit "Enviar"]

Now I want to validate the file* tag to be sure image width and height has some specific pixels.

A have code like this in my function.php to hook a validation:

add_filter( 'wpcf7_validate_file*', 'custom_file_validation_filter', 20, 2 );

function custom_file_validation_filter( $result, $tag ) {
    $tag = new WPCF7_FormTag( $tag );

    if ( 'archivo' == $tag->name ) {

                ====>  $img=getimagesize($file['tmp_name']); <=====

                $minimum = array('width' => '640', 'height' => '480');
                $width= $img[0];
                $height =$img[1];

        if ($width < $minimum['width']) {
            $result->invalidate( $tag, "Image dimension are to small. Minimum width is {$minimum['width']}px. Uploaded image width is $width px");
        } elseif ($height <  $minimum['height']) {
            $result->invalidate( $tag, "Image dimension are to small. Minimum height is {$minimum['height']}px. Uploaded image height is $height px");
        }        
    }

    return $result;
}

My problem is the line to get the current imagesize from the WPCF7 file tag. Anybody knows how can I get it?

closed as off-topic by Howdy_McGee Apr 27 '17 at 21:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Did you resolve this in the end? – Titan Apr 20 '17 at 8:38