JeVic
JeVic

Reputation: 681

Append Multiple input file upload upon browse

I am trying to append multiple files when the browse button is clicked but what happen is when I clicked the browse button and select multiple files again, the browsed file get reset(disappear) or get replaced with the new multiple browsed files. I am doing something similar to http://jsfiddle.net/aHrTd/4/ but instead of single file at a time, I would like to do multiple files at a time

<input id="file-upload-plans" type="file" class="file" multiple="multiple" name="floorplans[]" data-show-upload="false" data-show-caption="false" data-show-remove="true" accept="image/jpeg,image/png" data-browse-class="btn btn-default">

Upvotes: 0

Views: 3679

Answers (3)

Vahid Msm
Vahid Msm

Reputation: 1082

Here is a working demo and u can see outputs there.

$("#file").change(function() {
    var result = $(this)[0].files;
    for(var x = 0;x< result.length;x++){
       var file = result[x];
       // here are the files
        $("#output").append("<p>" + file.name + " (TYPE: " + file.type + ", SIZE: " + file.size + ")</p>");  
    }
    
});
p{
  background-color: cyan;
  font-family: open sans;
  max-width: 350px;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="file" id="file" name="file"  multiple="multiple"/>
<div id="output"></div>

Upvotes: 1

fzldn
fzldn

Reputation: 19

maybe this http://jsfiddle.net/aHrTd/67/ could help you

HTML

<form id="upload" action="upload.php" method="POST" enctype="multipart/form-data" onchange="addField();">
<label for="file">Soubor:</label>
<input type="file" name="files[]" class="file" /><br />
<input type="submit" name="Odeslat" value="Odeslat soubor" />
</form>

JS

$(function(){
    $(document).on('change', '.file', function(){
      var e = $(this);
      if(e.val()){
        e.clone().insertAfter(e);
      }
    });
  });

Upvotes: 1

kosman
kosman

Reputation: 78

I'm not 100% sure but you probably could save the added files with javascript. A few examples here.

https://developer.mozilla.org/en-US/docs/Web/API/FileList

Upvotes: 0

Related Questions