2

I have a file input element like this:

 <input name="fileupload[]" id="fileupload" type="file" multiple="" />

A user browses for their files and selects them, the files then appear in a list.

Now say a user wants to not add a particular file they hit a cancel button and it is deleted. That works but how do I remove the value from the fileupload input so that when they do upload the file that is meant to be deleted isn't added?

2 Answers 2

2

You could use javascript to place a hidden input with each separate file instead of holding them in an array initially, then attach an event handler onSubmit which could collect all the separate files and upload them.

When you need to delete a file from the 'queue' you could just use your javascript to remove the hidden input the same way you are removing it from the list.

If you'd like some code examples, please post some of your code to get us started - it is hard to post code for you if there is no indication of such things like which server side language you are using to handle the files and what javascript you are using to handle the client side code.

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

Comments

0

You cannot set the value(or clear the value) of a file-input, but you can replace the input with a new input, the effect would be the same.

2 Comments

But if I replace the input with a new one I would lose all the selected files inside it. They might have selected 10 files but then they want to remove just one of those files from the list.
That's the way it is, when the native behaviour of a file-input doesn't fit your need you must implement your own behaviour (XHR-upload by using the File-API: robertnyman.com/2010/12/16/…)

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.