Question

I'm fairly new to Zend Framework and I've encountered something strange, which I'm hoping somebody will be able to explain. Consider following code:

<? class Form extends Zend_Form
{
    public function init()
    {
    $upload = new Zend_Form_Element_File('upload');
    $this->addElement($upload);
    }    
}

if ($_POST)
{
    $form = new Form();
    var_dump($form->isValid($_POST));
    $values = $form->getValues();

    var_dump($_FILES, file_exists($_FILES['upload']['tmp_name']));
    exit;
}
?>
<form method="post" enctype="multipart/form-data">
    <input type="file" name="upload"/>
    <input type="submit" name="submit"/>
</form>

If uploading any file the var_dump of $_FILES will output that the uploaded file doesn't exist. Comment the $form->getValues() line, and it's there. After investigating the issue - getValues renames the actual file (ie. /tmp/php/phpBUI9M3) to whatever was the name of the uploaded file, keeping it in the same folder (ie. /tmp/php/test.png). Why? I was under the impression that getValues shouldn't alter any data.

PHP: 5.2.17, Zend: 1.10.4

Thanks!

Was it helpful?

Solution

From the manual:

Per default the file will automatically be received when you call getValues() on the form. The reason behind this behaviour is, that the file itself is the value of the file element.

http://framework.zend.com/manual/1.12/en/zend.form.standardElements.html#zend.form.standardElements.file

There are some examples of how to change this behaviour if that's not what you want to happen, but it seems logical to me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top