I have a form with several inputs that deal with files. The javascript validation is pretty good at checking to make sure that everything is good, but some things require PHP to inspect (like the file's mime type), and sometimes it will get rejected.
The problem is, when I send the user back to the form, I can repopulate all the data that they had originally input, except the inputs with the type of file. Firefox doesn't provide the absolute file path so I can't just copy in a file path to the input.
What can I do to repopulate the input type=file form elements?
You cannot populate the file input, to do so would be a serious security problem.
Instead, store the uploaded content on the server and store an id that you can use to reference it in a hidden input.
Clean the files up automatically after they reach a certain age, and provide a means for the user to change their mind about what file they want to upload (e.g. a checkbox (checked by default) for each file being stored on the server for upload)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With