Skip to content

Instantly share code, notes, and snippets.

@twxxk
Created December 7, 2008 13:54
Show Gist options
  • Save twxxk/33151 to your computer and use it in GitHub Desktop.
Save twxxk/33151 to your computer and use it in GitHub Desktop.
<?php
error_reporting(E_ALL | E_STRICT);
set_include_path(
dirname(__FILE__)
. PATH_SEPARATOR . dirname(__FILE__) . '/application/library'
. PATH_SEPARATOR . get_include_path()
);
include_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
$element = new Zend_Form_Element_File('foo');
$element
// ->setMultiFile(2)
->setLabel('Upload an image:')
->setDestination('d:\\temp')
// ->addValidator('Count', false, 2)
->addValidator('Size', false, 1024*1024*1024) // bytes
->addValidator('Extension', false, 'jpg,png,gif')
;
$form = new Zend_Form;
$form->setAttrib('enctype', 'multipart/form-data') // file upload
->setMethod('post')
->addElement($element, 'foo')
->addElement('submit', 'submit')
;
if (isset($_POST) && count($_POST))
{
// echo 'valid = ', (int)$form->isValid($_POST), "\n";
if ($form->isValid($_POST))
{
print_r($element->getValue());
}
}
$view = new Zend_View();
echo $form->render($view);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment