[QuickForm] upload example
| From: | Bertrand Mansion | Date: | Wed, 29 May 2002 11:18:44 +0000 |
| Subject: | [QuickForm] upload example | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-1506@lists.php.net to get a copy of this message | ||
<?php
require_once('HTML/QuickForm.php');
$form = new HTML_QuickForm('myform');
$form->addElement('file', 'myfile', 'Your file:');
$form->addElement('submit', 'submit', 'Send');
// optional : see registered rules
$form->addRule('myfile', 'File is required', 'uploadedfile');
$form->addRule('myfile', 'Cannot exceed 1776 bytes', 'maxfilesize',
1776);
$form->addRule('myfile', 'Must be XML', 'mimetype',
'text/xml');
$form->addRule('myfile', 'Must be *.xml', 'filename',
'/^.*\.xml$/');
if ($form->validate()) {
// optional : you can move and rename the uploaded file
$form->moveUploadedFile('myfile', '/tmp', 'testfile.txt');
echo '<pre>';
var_dump($form->_submitFiles);
echo '</pre>';
} else {
$form->display();
}
?>
Make sure you use the latest release (2.2) because otherwise you will have
to get rid of the validation rules.
Bertrand Mansion
Mamasam