フォームを作成するときは、フォームで次のようにします。
$image = $this->getElement('image');
//$image = new Zend_Form_Element_File();
$image->setDestination(APPLICATION_PATH. "/../data/images"); //!!!!
$extension = $image->getFileName();
if (!empty($extension))
{
$extension = @explode(".", $extension);
$extension = $extension[count($extension)-1];
$image->addFilter('Rename', sprintf('logo-%s.'.$extension, uniqid(md5(time()), true)));
}
$image
->addValidator('IsImage', false, $estensioni)//doesn't work on WAMPP/XAMPP/LAMPP
->addValidator('Size',array('min' => '10kB', 'max' => '1MB', 'bytestring' => true))//limit to 200k
->addValidator('Extension', false, $estensioni)// only allow images to be uploaded
->addValidator('ImageSize', false, array(
'minwidth' => $img_width_min,
'minheight' => $img_height_min,
'maxwidth' => $img_width_max,
'maxheight' => $img_height_max
)
)
->addValidator('Count', false, 1);// ensure that only 1 file is uploaded
// set the enctype attribute for the form so it can upload files
$this->setAttrib('enctype', 'multipart/form-data');
次に、コントローラーでフォームを送信すると、次のようになります。
if ($this->_request->isPost() && $form->isValid($_POST)) {
$data = $form->getValues();//also transfers the file
....