Search code examples
phpzend-formzend-form-element

Zend_Form_Element_File and "File exceeds the defined ini size" issue


I'm using Zend_Form_Element_File to validate certain file properties. The file input element in question is created dynamically - ie. it can be in the form, but doesn't need to; however, if it is, and a file has been submitted via it, it needs to meet certain criteria.

I've encountered the "File exceeds the defined ini size" issue, when the form doesn't contain the file element. Is it an intended behavior?

Please bear in mind that the FormUpload should validate for both form elements. I can use different Zend_Forms, depending on the $_FILES array being empty (or not), but it feels like a poor solution, seeing that Zend_Form should validate the data / data fields for me.

Code to replicate the issue:

<?php

class FormUpload extends Zend_Form
{
    public function init()
    {
        $upload = new Zend_Form_Element_File('upload');
        $upload->setRequired(false);
        $this->addElement($upload);
    }
}

var_dump($_POST, $_FILES);
if (!empty($_POST))
{
    $form = new FormUpload();

    if ($form->isValid($_POST))
    {
        $values = $form->getValues();
        var_dump($values);
    }
    else
        var_dump($form->getMessages());
}

?>

<form method='post' enctype="multipart/form-data">
    <input type='hidden' name='something' value='something'/>
    <input type='submit' value='submit'/>
</form>

<form method='post' enctype="multipart/form-data">
    <input type='file' name='upload'/>
    <input type='submit' value='submit'/>
</form>

I'd treat it as a bug - the solution to this problem is to always have an input field with the validated name; otherwise this error will occur.


Solution

  • As I've stated in the edit: I'd treat it as a bug - the solution to this problem is to always have an input field with the validated name; otherwise this error will occur (which doesn't have anything to do with the issue).