Wednesday, April 14, 2010

File Upload with Zend Framework

If you are using a more recent version of Zend Framework (i.e. 1.10), don't make the
same mistake that I have made at least three times now.

First, call isValid. THEN, call receive(). From what I can tell, there is a Validator on the file object, which verifies the existence of the file in the tmp folder. However, when you call receive(), the file is moved to the destination folder.

So, your code should look something like this:

if($form->isValid($this->getRequest()->getParams())) {

if ($form->name->receive()) {
// create success message here
// or create a Zend_Filter_File_Rename
}
}


File uploads in Zend has been a very challenging problem to me. I'd like to blame the documentation, but Thomas Weidner would not appreciate that very much.

No comments:

Post a Comment