Zend 表单多文件上传不起作用

Zend form multiple file upload not working

我想创建一个图片上传来上传多张图片,用户需要多少张都可以。

这是我目前所拥有的。

$this->addElement('file', 'images',
    array(
        'label'         => $this->getView()->Translate('This_Label'),
        'valueDisabled' => true,
        'multiple'      => true,
        'validators'    => array(
            ['Extension', false, 'jpg,png,gif'],
        )
    )
);

然而,即使该元素允许多个上传仍然只收到一个。坚持我的代码如下,但我仍然只调试了最后一个文件。

$this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);

$upload = new Zend_File_Transfer_Adapter_Http();
$files  = $upload->getFileInfo();
foreach ($files as $file => $fileInfo){
    if ($upload->isUploaded($file)) {
        if ($upload->isValid($file)) {
            if ($upload->receive($file)) {
                $info = $upload->getFileInfo($file);
                $tmp  = $info[$file]['tmp_name'];
                Zend_Debug::dump($info, $tmp);
            }
        }
    }
}

如何让元素上传多个文件? 我想要一个原生的 Zend_Form 元素,但不想要一个重复的元素(就像参数 multiFile 那样)。

找到解决方案,它与 Zend 本身没有太大关系。 问题在于元素不是 images[].

所以解决方案是添加属性 isArray = true 如下:

$this->addElement('file', 'images',
    array(
        'label'         => $this->getView()->Translate('This_Label'),
        'valueDisabled' => true,
        'isArray'       => true,
        'multiple'      => true,
        'validators'    => array(
            ['Extension', false, 'jpg,png,gif'],
        ),
    )
);