ZF-7851: Call to Zend_Form_Element::receive() and then Zend_Form::getValues causes Zend_Validate_File_Count to count 2 files


Zend_Validate_File_Count shows an error prematurely like this: "Too much files, maximum '1' are allowed but '2' are given"

This can be done in 2 ways

  1. Call Zend_Form_Element::receive() then call Zend_Form->getValues()

  2. Call Zend_Form->getValues twice

What happens is the first call adds the temporary file path to Zend_Validate_File_Count /tmp/phpwlAZqc

The second call adds the real file name /tmp/picture.jpg

I do understand that getValues tries to process the form, but should I not be able to call it twice on the same instance? Or sometimes you want to check of the file was received first with Zend_Form_Element::receive() then collect the form data with Zend_Form->getValues(). If it shouldn't something should be done about multiple calls. Took a while to track this down.

Reproducible code below.

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(dirname(__FILE__) . '/../../library'),

/** Zend_Loader_Autoloader */
require_once 'Zend/Loader/Autoloader.php';
//automatically registers Zend

$form = new Zend_Form();
$file = new Zend_Form_Element_File('picture');
// ensure only 1 file
$file->addValidator('Count', true, 1);

$submit = new Zend_Form_Element_Submit('save');

if($form->isValid($_POST) && $form->picture->receive()){
    var_dump($form->getValues()); //THIS CAUSES THE COUNT ERROR

echo $form->render(new Zend_View());


Added some additonal information

There is a logical description for this irritation: Before the file has been uploaded, it is physically not available. Therefor it is counted with the temporary name.

After the upload, it is physically available, and the real name is counted.