Search code examples
phphtmlpearquickform

PEAR HTML Quickform - Default File Upload path


I am using PEAR HTML Quickform for various forms on my php website.

One of the issue I am having is that if a user select a file to upload (button Browse...) and submit while he forgot to fill a required field, the form is reloaded with all the info and an error message, but for the file. So he has to browse once again that same file before submitting again.

I am wondering if there was something to prevent that, in HTML Quickform or even with other work around you could think of. Basically I imagine trying to default the file path the user selected before submitting. But then again, is it possible to "default" a file field ?


Solution

  • Defaults for a file upload field are not possible for security reasons; this is a browser limitation. Otherwise you could pre-fill a hidden form with /etc/passwd or other system files and auto-submit them via javascript :)


    You can only try handle the file even in the case of an form error, and modify the form to not have a file upload field anymore (and show the uploaded file).

    But then you also have to clean up in case the form never gets submitted again.