Re: Re: Quickform - File uploads
| From: | Bertrand Mansion | Date: | Tue, 02 Sep 2003 07:14:46 +0000 |
| Subject: | Re: Re: Quickform - File uploads | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-7533@lists.php.net to get a copy of this message | ||
<leonie_price@hotmail.com> wrote :
> Just so you know, here is my code so far:
>
> $form = new HTML_QuickForm('import_excel', 'post');
> $form->addElement('file', 'xls_file', 'File:');
$file =& $form->addElement('file', 'xls_file', 'File:');
Keep a reference to the file element to be able to work with it later.
> $form->addRule('xls_file', 'You must select a file',
> 'required');
$form->addRule('xls_file', 'You must select a file',
'uploadedfile');
Required is called uploadedfile for file elements.
> $form->addElement('submit', 'btnUpload', 'Upload');
> if ($form->validate()) {
> # If the form validates then freeze the data
> $form->freeze();
There is no freeze for file elements. Unless you can tell me how it should
look like when frozen.
> $form->process('process_data', false);
> }
> else {
> $form->display();
> }
>
> function process_data($values) {
> global $form;
Here you can make $file global instead.
> if ($form->isUploadedFile('xls_file')) {
if ($file->isUploadedFile()) {
> $x = $form->moveUploadedFile('xls_file', 'E:/temp');
$x = $file->moveUploadedFile('E:/temp');
> print $x;
> }
> else
> {
> print "No file uploaded";
> }
> }
>
>
> Works ok, but it would be nice to fix up the validation.
Hope this helps
Bertrand Mansion
Mamasam