Zend Framework2中的“IsImage validation”或“MimeType Validator”

I am using formFilter method (factory method) to validate forms in Zend Framework 2. Please somebody help to add file upload validation.

Please specify how to use "IsImage validation" or "MimeType Validator" inside formfilter.

Try this

public function getInputFilter()
{
    if (!$this->filter) {
        $this->filter = new InputFilter();
        $factory = new InputFactory();
        $this->filter->add($factory->createInput(array(
                    'name' => 'image',
                    'required' => true,
                    'validators' => array(
                        array(
                            'name' => 'NotEmpty',
                            'options' => array(
                                'messages' => array(
                                    'isEmpty' => 'Please select an icon to upload.',
                                ),
                            ),
                        ),
                        array(
                            'name' => '\Zend\Validator\File\IsImage',
                            'options' => array(
                                'messages' => array(
                                    'fileIsImageFalseType' => 'Please select a valid icon image to upload.',
                                    'fileIsImageNotDetected' => 'The icon image is missing mime encoding, please verify you have saved the image with mime encoding.',
                                ),
                            ),
                        ),
                    ),
        )));
    }
    return parent::getInputFilter();
}

Link