How to get each file data in jQuery when I select multiple files?

How to get each file data when I select multiple files?

<input name="file" type="file" multiple="" >

<script type="text/javascript">
$(document).ready(function(){
  $(':file').change(function(){
    var file = this.files[0];
    name = file.name.toLowerCase();
    size = file.size;
    type = file.type;
  });
});
</script>

Answers


this.files will produce an array. So just loop through like this...

$(document).ready(function(){
  $(':file').change(function(){
    for(var i=0; i< this.files.length; i++){
       var file = this.files[i];
       name = file.name.toLowerCase();
       size = file.size;
       type = file.type;
    }
  });
});

You can try this -

$(':file').change(function(){
    var fileArray = this.files;
    $.each(fileArray,function(i,v){
      name = v.name.toLowerCase();
      size = v.size;
      type = v.type;
      alert(name);
    })
});

Need Your Help

converting text field from latin1_swedish to utf8?

mysql unicode collections utf-8

Hi guys is there a safe way to convert a table from latin1_swedish to fully utf8?

jQuery .add method

jquery jquery-animate add

I'm writing a simple jQuery plugin that displays images with a specific class in the center of the screen (when clicked, full-sized) with a gray overlay around the image. When we click on the overl...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.