3

我正在使用 formFilter 方法(工厂方法)来验证Zend Framework 2中的表单。请有人帮助添加文件上传验证。

请指定如何在 formfilter 中使用“ IsImage 验证”或“ MimeType Validator ”。

4

1 回答 1

5

试试这个

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();
}

关联

于 2013-04-26T11:49:34.200 回答