ZF-11707: Disabling input type="file" in a form causes zend_file_transfer_adapter_http::isValid to enter workaround block of code and returning false (not validating)

Issue Type: Bug Created: 2011-08-30T10:34:41.000+0000 Last Updated: 2012-10-15T06:33:15.000+0000 Status: Resolved Fix version(s): - Next Major Release ()

Reporter: Jarek Nowisz (jarek) Assignee: Thomas Weidner (thomas) Tags: - Zend_File_Transfer

  • After1.12.0

Related issues: Attachments:


In Zend_File_Transfer_Adapter_Http::isValid() there is a block with comment: "// Workaround for a PHP error returning empty $_FILES when form data exceeds php settings" This workaround is executed not only when form data exceeds php settings, but also when you submit a form with 1 disabled file element and other non file element.

The condition for entering workarund should also check if sttings were exceeded.

This bug is somewhat connected to: #ZF-10279.

After submitting a form with a single file element which is not required and disabled, and other, non file elements, $_FILES is an empty array. Having empty array in $_FILES, Zend_File_Transfer_Adapter_Http::_prepareFiles() produces empty array in Zend_File_Transfer_Adapter_Http::_files.

Since $_POST is not empty (because of other, non file form elements), condition: "if (empty($this->_files) && ($content > 0)) {" is true in Zend_File_Transfer_Adapter_Http::isValid(), and isValid returns false.


Posted by Thomas Weidner (thomas) on 2011-08-30T13:59:16.000+0000

Zend_File does not know about Zend_Form_Element. When Zend_Form says that there is an file element which has to be validated Zend_File tries to validate it (as it is called by Zend_Form).

My expectation is that validations should NOT BE PROCESSED/DONE for disabled elements. Therefor I don't see this as failure from Zend_File but from Zend_Form which should not try to validate an disabled element.

Posted by Thomas Weidner (thomas) on 2011-09-03T21:50:29.000+0000

Please give an example of your problem. How do you disable a special input type?

Posted by Thomas Weidner (thomas) on 2011-09-29T16:32:05.000+0000

Fixed with GH-388

Posted by Aurimas (aur1mas) on 2012-06-21T11:07:25.000+0000

Is this problem really solved in 1.x version?

I'm trying to submit form with disabled file field & still get errors using latest (1.11.11) ZF version.

My Code:

<pre class="highlight">
$form = new Zend_Form();
$title = new Zend_Form_Element_Text('title');
$file = new Zend_Form_Element_File('file');
  ->setAttrib('disabled', true)
$submit = new Zend_Form_Element_Submit('submit');

When trying to validate form I get error: 'fileUploadErrorIniSize' => string 'File 'file' exceeds the defined ini size'

Posted by Adam Lundrigan (adamlundrigan) on 2012-06-21T12:50:33.000+0000

Fix needs to be backported from ZF2

Posted by Jarek Nowisz (jarek) on 2012-06-22T06:47:24.000+0000

You can use this simple workaround before calling isValid():

<pre class="highlight">
if(!isset($_FILES[$form_element_name])) {
    $_FILES[$form_element_name] = array(
                  'name' => '',
                  'type' => '',
                  'tmp_name' => '',
                  'error' => 4,
                  'size' => 0);

Posted by Behrang No (behrang) on 2012-10-15T06:33:15.000+0000

this is not work for me the post data $this->getRequest()->getPost() return: array 'exam' => array 'exam_id' => string '' (length=0) 'exam_dates_id' => string '' (length=0) 'disability' => string '0' (length=1) 'save' => string 'Save and continue' (length=17) 'MAX_FILE_SIZE' => string '8388608' (length=7) but var_dump($_FILES); return empty !

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.