我有一个接受文字字段和图片的表单,我希望能够验证或过滤上传的图片。
我尝试在GitHub上使用本教程(https://github.com/lowtower/zend-expressive2-tutorial)
我正在使用zend表达2.我有这种方法:
<?php
namespace Admin\Model\InputFilter;
use Zend\InputFilter\InputFilter;
class EventoInputFilter extends InputFilter
{
public function init()
{
$this->add([
'name' => 'eventoNombre',
'required' => true,
'filters' => [
['name' => 'StripTags'],
['name' => 'StringTrim'],
],
'validators' => [
[
'name' => 'StringLength',
'options' => [
'min' => 5,
'max' => 100,
],
],
],
]);
$this->add([
'name' => 'imagenes[]',
'required' => true,
'validators' => [
[
'name' => 'FileUploadFile'
],
[
'name' => 'FileMimeType',
'options' => [
'mimeType' => ['image/jpeg', 'image/png']
]
],
[
'name' => 'FileIsImage'
],
[
'name' => 'FileImageSize',
'options' => [
'minWidth' => 128,
'minHeight' => 128,
'maxWidth' => 4096,
'maxHeight' => 4096
]
],
],
'filters' => [
[
'name' => 'FileRenameUpload',
'options' => [
'target' => 'public/eventos/',
'useUploadName' => true,
'useUploadExtension' => true,
'overwrite' => true,
'randomize' => false
]
]
],
]);
}
}
但是出了问题,当我上传正确的图片时,我没有正确验证它。