Javascript Reference - HTML DOM Input FileUpload files Property








The read-only files property returns a FileList object representing the file or files selected bt the file upload button.

Browser Support

files Yes 10.0 Yes Yes Yes

Syntax

var v = fileuploadObject.files 

Return Value

A FileList object that represents the selected file or files.





Example

The following code shows how to display information about the selected files.


<!DOCTYPE html>
<html>
<body onload="myFunction()">
<input type="file" id="myFile" multiple size="50" onchange="myFunction()">
<script>
function myFunction(){<!--from  w w w  . ja  va  2  s .c om-->
    var x = document.getElementById("myFile");
    if ('files' in myFile) {
        if (x.files.length == 0) {
            console.log("No files selected. Select one or more files.");
        } else {
            for (var i = 0; i < x.files.length; i++) {
                var file = x.files[i];
                if ('name' in file) {
                    console.log("name: " + file.name);
                }
                if ('size' in file) {
                    console.log("size: " + file.size + " bytes");
                }
            }
        }
    }else {
        if (x.value == "") {
            console.log("Select one or more files.");
        } else {
            console.log("The files property is not supported by your browser!");
        }
    }
}
</script>
</body>
</html>

The code above is rendered as follows: