0

I have a HTML file field <input name="File" id="FileName" type="file"/>. When I submit the form, I do receive the file, all fine. However, when I validate the user's input and cannot accept the values provided, I will need another round trip. As usual, I will redisplay the form plus error messages.

For text field or textarea I can set the (already) provided value, e.g. by value or just echo the value in the textarea. How could I do the same for file fields? I want to avoid that the user always has to reselect the file in the browser.

-- added --

Comments below are right - there are workarounds described in the mentioned SO questions:

  1. PHP remember file field contents
  2. Can you re-populate file inputs after failed form submission with PHP or JavaScript?
  3. Restoring the value of a input type=file after failed validation
Community
  • 1
  • 1
Horst Walter
  • 13,663
  • 32
  • 126
  • 228
  • 2
    check http://stackoverflow.com/questions/1326683/php-remember-file-field-contents – Cris Feb 19 '13 at 11:27
  • 2
    Duplicate of http://stackoverflow.com/questions/6842571/can-you-re-populate-file-inputs-after-failed-form-submission-with-php-or-javascr and http://stackoverflow.com/questions/4205634/restoring-the-value-of-a-input-type-file-after-failed-validation – Heap Feb 19 '13 at 11:27
  • Cris and Heapy are right, can be closed as duplicate. The workarounds provided are well explained. – Horst Walter Feb 19 '13 at 11:32

1 Answers1

1

This is not possible - you have to store the file on the server to do this. Then you can show the user a short info about the already stored file and the option to upload a new file or delete the file

Philipp
  • 15,377
  • 4
  • 35
  • 52
  • Yep, seems to be right, was trying to store the path via Js, but even this failes: onChange= "alert( document.getElementById('FileName').value );" does provide a fake path, not the original upload path. – Horst Walter Feb 19 '13 at 11:57