Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework2 ZF2验证程序文件由\Zend\File\Transfer\Adapter\Http_Zend Framework2 - Fatal编程技术网

Zend framework2 ZF2验证程序文件由\Zend\File\Transfer\Adapter\Http

Zend framework2 ZF2验证程序文件由\Zend\File\Transfer\Adapter\Http,zend-framework2,Zend Framework2,我有一个HTML代码2的输入文件在一个行动的看法 <form action="#" id="appForm" name="appForm" enctype="multipart/form-data" method="post"> <input type="file" name="picture" id="picture"> <input type="file" name="attach_file" id="attach_file"> </

我有一个HTML代码2的输入文件在一个行动的看法

<form action="#" id="appForm" name="appForm"
        enctype="multipart/form-data" method="post">
<input type="file" name="picture" id="picture">
<input type="file" name="attach_file" id="attach_file">
</form>
和ArticleValidator中的代码

    namespace Admin\Form;

class ArticleValidator {

protected $_arrError = null;
protected $_arrData;

public function __construct($arrParam = array(), $options = null) {

    // avatar
    if (!empty($arrParam['picture']['name'])) {
        $size = new \Zend\Validator\File\Size(array('min' => 1, 'max' => 2097152));
        $ext = new \Zend\Validator\File\Extension('gif,jpg,jpeg,png');
        $adapterPicture = new \Zend\File\Transfer\Adapter\Http();
        $adapterPicture->setValidators(array($size, $ext), $arrParam['picture']['name']);
        if (!$adapterPicture->isValid()) {
            $message = $adapterPicture->getMessages();
            $this->_arrError['picture'] = current($message);
            $arrParam['picture'] = '';
        }
    }

    // attach_file
    if (!empty($arrParam['attach_file']['name'])) {
        $size = new \Zend\Validator\File\Size(array('min' => 1, 'max' => 5242880));
        $ext = new \Zend\Validator\File\Extension('rar,zip,gz,docx,pdf,xlsx');
        $adapterFile = new \Zend\File\Transfer\Adapter\Http();
        $adapterFile->setValidators(array($size, $ext), $arrParam['attach_file']['name']);
        if (!$adapterFile->isValid()) {
            $message = $adapterFile->getMessages();
            $this->_arrError['attach_file'] = current($message);
            $arrParam['attach_file'] = '';
        }
    }
}

}
当我将有效图像发布到“图片”字段时$此->\u错误将包含“文件“”未上载”。我检查并知道,$adapterPicture也检查“附加文件”字段。因为我没有将文件发布到“attach_file”中,所以它会说notupload(对于attach_file)。 那么,我如何只检查“picture”字段,然后只检查“attach_file”。
PS:我不使用Zend\Form。只有一个HTML代码,输入类型为2=file。然后,检查file use\Zend\file\Transfer\Adapter\Http

为什么不使用
Zend\Form
对象?@AlexP,因为它是必需的。所以,我必须只使用HTML,而不是Zend\Form。我打印它,我看到,它会自动在每个文件中添加Zend\Validator\File\Upload。但我只添加了每个适配器单独的验证器。那么,如何使用每个验证器验证每个文件
    namespace Admin\Form;

class ArticleValidator {

protected $_arrError = null;
protected $_arrData;

public function __construct($arrParam = array(), $options = null) {

    // avatar
    if (!empty($arrParam['picture']['name'])) {
        $size = new \Zend\Validator\File\Size(array('min' => 1, 'max' => 2097152));
        $ext = new \Zend\Validator\File\Extension('gif,jpg,jpeg,png');
        $adapterPicture = new \Zend\File\Transfer\Adapter\Http();
        $adapterPicture->setValidators(array($size, $ext), $arrParam['picture']['name']);
        if (!$adapterPicture->isValid()) {
            $message = $adapterPicture->getMessages();
            $this->_arrError['picture'] = current($message);
            $arrParam['picture'] = '';
        }
    }

    // attach_file
    if (!empty($arrParam['attach_file']['name'])) {
        $size = new \Zend\Validator\File\Size(array('min' => 1, 'max' => 5242880));
        $ext = new \Zend\Validator\File\Extension('rar,zip,gz,docx,pdf,xlsx');
        $adapterFile = new \Zend\File\Transfer\Adapter\Http();
        $adapterFile->setValidators(array($size, $ext), $arrParam['attach_file']['name']);
        if (!$adapterFile->isValid()) {
            $message = $adapterFile->getMessages();
            $this->_arrError['attach_file'] = current($message);
            $arrParam['attach_file'] = '';
        }
    }
}

}