Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Individual Files When Multiple FIles Are Selected With File Input

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?

like image 894
Lukas Avatar asked Nov 14 '22 03:11

Lukas


1 Answers

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.

like image 173
raina77ow Avatar answered Nov 16 '22 04:11

raina77ow