How do we get name,size,type information of uploaded files through javascript | Techbirds

Posted on: May 14, 2014 /

Categories: JavaScript, PHP / Author Name: Diksha Verma

In this post, I am going to explain you how can we get all information of uploaded files like name,size,type  on button click.

In this form,we have two button

1) Input type file button through which we can upload multiple files

2)Input type button:  On click of this button we call getFileNames() function

3)getFileNames() function gives the name,size,type  of uploaded files.

Function getfileNames()

In this function,

file[i].name :  gives names of uploaded files

file[i].size : gives size of uploaded files

file[i].type : gives type of uploaded files

function getFileNames(){ var files = document.getElementById(“files”).files; //alert(files); var names = “”; for(var i = 0; i < files.length; i++) { alert(files[i].name); alert(files[i].size); alert(files[i].type); names += files[i].name + ” “; alert(names); } }

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

function getFileNames(){

    var files = document.getElementById(“files”).files;

//alert(files);

    var names = “”;

    for(var i = 0; i < files.length; i++)

    {

     alert(files[i].name);

     alert(files[i].size);

     alert(files[i].type);

    names += files[i].name + ” “;

    alert(names);

    }

}

897 total views, 1 views today

Share this Onfacebook-3420006twitter-6587114linkedin-1951048google-5594651