WordPress Contact Form 7图像尺寸验证

时间:2018-07-05 14:33:47

标签: forms image validation contact

我想先验证图像的高度和宽度,然后再将其上传到联系表格7中。 我在网上找到了此代码,但是当我尝试将其添加到主题functions.php中时,出现此错误:

  

语法错误,意外的'==='(T_IS_IDENTICAL)

这是代码:

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

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

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

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

                $minimum = array('width' => '300', 'height' => '300');
                $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;
}

0 个答案:

没有答案