5

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?

10
  • You are talking about using Javascript, right? You should tag it as that if that's the case (and I don't know of another way to handle it otherwise). Commented Jun 23, 2012 at 21:22
  • I'm sorry, to remove by what exactly user action? If he clicks on that input control again, he may just choose the list of files again. Commented Jun 23, 2012 at 21:23
  • Take note that browsers are usually very restrictive about what may be actually changed by JavaScript in the input=file control value. Commented Jun 23, 2012 at 21:24
  • imgdiode.com/MiB9QK The file should be removed when the red "x" is clicked. Commented Jun 23, 2012 at 21:24
  • How the names of the files are written here? Are these the files already uploaded? Commented Jun 23, 2012 at 21:27

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.