6

Say I have a form that allows users to upload multiple images, which are appended with an option to remove them if they don't want to upload that particular photo.

Is it possible to remove the value from the files object of the one that they removed (e.g. didn't want to upload)?

bob_cobb
  • 2,229
  • 11
  • 49
  • 109
  • Did you try to remove ``? If, of course, your form consists of a set of the standard file inputs. – Cheery Feb 18 '12 at 04:13
  • Possible duplicate of [How to remove one specific selected file from input file control](https://stackoverflow.com/questions/19060378/how-to-remove-one-specific-selected-file-from-input-file-control) – Endless Dec 09 '17 at 12:57

3 Answers3

5

FileList has no API to remove entries:

https://developer.mozilla.org/en/DOM/FileList

However you can reconstruct File uploader using XHR2 and AJAX and filter in content there. This implies doing XHR2 and AJAX upload and is not suitable for traditional <form> uploads.

https://developer.mozilla.org/en/Using_files_from_web_applications

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
1

Libraries are your best bet before we get some standard API...

They are also available at https://cdnjs.com/

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
1

If you are using a standard form with a set of standard file inputs then you can do it like this http://jsfiddle.net/thXre/

$(document).ready(function(){
    $('.remove').click(function(){
        $(this).closest('div').slideUp('slow', function(){$(this).remove();});
    });        
});​

and html code:

<div>
 <input type='file' name='files[]'> <img src='x.gif' class='remove'>
</div>
<div>
 <input type='file' name='files[]'> <img src='x.gif' class='remove'>
</div>
<div>
 <input type='file' name='files[]'> <img src='x.gif' class='remove'>
</div>
Cheery
  • 16,063
  • 42
  • 57
  • Thanks, I know how to remove the actual elements, but it's removing them from being included in the upload that I was interested in which FileList takes care of. – bob_cobb Feb 18 '12 at 05:53