kalpaitch
kalpaitch

Reputation: 5271

re-attaching files input to an html form

I have a rather extensive form which contains a file input. The form will be returned if there are errors and all the other inputs will be repopulated with the existing $_POST data. It is not possible to re-populate and image input.

Does anyone have any suggestions on how resend the posted file without storing it temporarily on the server (otherwise there could be a large build up of temporary files).

Cheers,

Upvotes: 0

Views: 50

Answers (2)

Damp
Damp

Reputation: 3348

You don't really have a way around that... You have two options here.

  1. Do client side form validation (w/ajax if necessary) so that you ensure that the form's content is valid before you submit the form
  2. Store the file temporary on the server (deleting files older than 30 mins or so...)

Upvotes: 1

Quentin
Quentin

Reputation: 943624

You could encode the files using the data: scheme, then stuff that in a hidden input in the form.

… but that would be a horrible waste of bandwidth (especially if the files are on the large side).

Storing temp files and having a sane housekeeping policy (such as delete all files over 10 minutes old every 5 minutes) is the way forward.

Upvotes: 1

Related Questions