twxxk (owner)

Revisions

gist: 33151 Download_button fork
public
Public Clone URL: git://gist.github.com/33151.git
Embed All Files: show embed
Zend_Form_Element_File_sample.php #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?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);