我正在使用formFilter方法(工厂方法)来验证 Zend Framework 2 中的表单。请有人帮助添加文件上传验证。
请在formfilter中指定如何使用“ IsImage validation ”或“ MimeType Validator ”。
答案 0 :(得分: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();
}