swordz
Jan 7 2009, 12:58 AM
This possibly doesn't have a solution, but it's worth a try...
I have a form that includes a file upload option. If something is not filled correctly, the form re-appears with various error messages, and everything filled in with the previous answers, on the basis that it'll probably be a minor change. How do I make the same happen with the file upload so they don't have to browse for it?
Tbh I don't think that the $_FILES give enough information for this to be possible - if I upload C:/someroute/file.txt then $_FILES['file']['name'] = file.txt, and that's really all I've got to go on. Any other way?
Thanks,
swordz
I don't think there's a cross browser way, I believe IE sends the full path in its raw POST data, so within IE you might be able to just grab the value via javascript and set a hidden field within the form but within Gecko based browsers you could only get the filename, you're better off letting them select the file again.
Alex
Jan 7 2009, 05:46 PM
We discussed this in IRC around when this was posted, and the only realistic cross-browser way I could think of would be to take the file and upload it to a temporary location regardless of form validation success and register it with a simple database table of the form:
tmp_uploads(id, filename, ipaddr, timestamp)
Then when the user failed validation, they could be given the option to continue using the file they have just used. If they choose to use it, then they needn't select another and the file will simply be moved. If they decide to use something else the file will be discarded. If they leave at this point the file will be cleaned up after a determined expiry time worked out from the timestamp field using cronjobs.
Would be interested if there is an easier way that would work everywhere (including when JS is disabled).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.