Tuesday, August 18, 2009

Zend_Form multiple file uploads

This blog I'm starting with this mini tutorial. Recently I have started using Zend Framework as my main PHP framework. Testing it and playing with different components I decided to create something useful. I created simple form where users could upload more than one file, I started googling how to achieve this. Found some nice tutorials but they did not suited for my needs.
After some time of experiments I ended with this code.

In form class i created files fields by adding these lines of code in my class:

//image upload field1
$this->files = new Zend_Form_Element_File('files');
$this->files->setLabel('Select files to upload')
->addValidator(new Zend_Validate_File_IsImage)
->addValidator(new Zend_Validate_File_Size('2MB'))
->addValidator('Count', 3);