1

I want to create a image upload to upload multiple images, as many as the user requires.

This is what i have so far.

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

However even though the element allows multiple the upload still recieves only one. On the persist my code is as follow, but still i only get the last file debugged.

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

How can i make the element upload multiple files? I want a native Zend_Form element, but dont want a repeated element (like the param multiFile does).

1 Answer 1

2

Found the solution, it wasn't that much related to Zend itself. The issue lay in the element not being images[].

So the solution was to add the attrib isArray = true as followed:

$this->addElement('file', 'images',
    array(
        'label'         => $this->getView()->Translate('This_Label'),
        'valueDisabled' => true,
        'isArray'       => true,
        'multiple'      => true,
        'validators'    => array(
            ['Extension', false, 'jpg,png,gif'],
        ),
    )
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.