Issues

ZF-7201: Zend_Form_Element_File::getValue() only works on first usage

Description

If you are accessing the ::getValue() function of Zend_Form_Element_File more than once during one PHP process only the first usage of the function will return the correct value of the element. All subsequent usages will return NULL. At the end I tried the calling the function on the consequtive lines - with above result.

The actual problem seems to lie in the Zend_File_Transfer_Adapter_Http::receive function. The Zend_Form_Element_File::receive() function only returns TRUE once. That's why Zend_Form_Element_File::geValue() will return NULL in LINE 711 on the second usage.

Comments

I can negotate your bescribed reason.

receive() returns TRUE multiple times. The object stores if the file was already received or not, and in the case it has already been received a true is instantly returned without further checks.

BUT: When you create a new object then you will have the described behaviour, as the new object expects that the file is available, which is not the case as the first object already received the file.

Then my trace of the problem to the transfer adapter seems to be wrong. Still I have the feeling that it should be possible to access the value of an instance of Zend_Form_Element_File more than once. Currently this behaviour is like follows:

Example: Upload of a file named "file.gif" via an file upload field named "image". Codesnippet:

// $form = new Zend_Form(); .... $value1 = $form->image->getValue(); $value2 = $form->image->getValue(); //

In this example $value1 is "file.gif" and $value2 is NULL. This wasn't the case in the 1.7.+ branch and actually broke part of my application after the upgrade to 1.8.4. I changed my application to use Zend_Form_Element_File::getFileName(null, false) instead of the ::getValue(). That works for the moment.

Fixed with r16542