Re: QuickForm - display uploaded filename
| From: | Bertrand Mansion | Date: | Mon, 10 Mar 2003 14:13:51 +0000 |
| Subject: | Re: QuickForm - display uploaded filename | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-4129@lists.php.net to get a copy of this message | ||
<bruckmann@solum.de> wrote :
> Hi,
>
> I would like to display the name of an uploaded file after the form
> submission and I'm not sure if I missed a QuickForm feature doing this. Is
> there any? That's how I do it (other fields and code skipped, QuickForm
> 2.10):
>
> if ($form->validate()) {
> // get name of uploaded file
> $assetName = $form->_submitFiles['asset']['name'];
I've added a getUploadedFile('asset'); method in version 2.10.
> // add element for displaying the name of the uploaded file
> $form->addElement('text', 'assetorigin', 'uploaded Asset:');
Be extra careful not to use the 'assetorigin' value in your code as this can
lead to some security problems. You might store the file path in a secure
place (ie. session vars or DB). Or divide your form in 2 parts. File
elements are not meant to be frozen.
> // set value of the new element to the name of the uploaded file
> $defaultValues['assetorigin'] = $assetName;
>
> // remove submit button
> $form->removeElement('submit', true);
>
> // remove file element since the value cannot be set
> $form->removeElement('asset', true);
>
> // freeze and display the form
> $form->freeze();
> $form->display();
> }
>
Good luck,
Bertrand Mansion
Mamasam