Is it possible to remove individual files from the list of files to be uploaded when the user is allowed to select multiple files? For example, I have an input that looks somewhat like that:
<input type = 'file' name = 'file' id = 'file' multiple = 'multiple' />
And the user selects 4 photos, 1.jpg, 2.jpg, 3.jpg and 4.jpg. Is it possible to remove 4.jpg, because the user changed their mind and doesn't want to upload that one?
The short answer would be just 'No'. It's not possible to change the value of file input
element from a script: it would be a security hole size of a mammoth otherwise. And let me assure you: some browsers (IE, that's about you!) become VERY picky when dealing with file inputs.
But you can use the following approach: let users upload as many files as you and they want (it's prudent to set some limits, though), but put them into some temporary storage. Only when users actually express their desire to save the entity to which these files are attached, move these files into a permanent state.
Or may be it's time to think about using some fallback mechanisms, Flash or something like that. In fact, there's another reason to do it: IE8 doesn't support multiple
attribute on the file picker.
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