Input FileUpload files attribute

Definition and Usage

files This property returns a FileList object representing one or more files selected using the file upload button.

Through the FileList object, you can get the name, size, and content of the file.

This property is read-only.

Example

Use the file upload button to select one or more files and display information about the selected files:

var x = document.getElementById("myFile");
var txt = "";
if ('files' in x) {
  if (x.files.length == 0) {
    txt = "Please select one or more files.";
  } else {
    for (var i = 0; i < x.files.length; i++) {
      txt += "<br><strong>" + (i+1) + ". file</strong><br>";
      var file = x.files[i];
      if ('name' in file) {
        txt += "Name: " + file.name + "<br>";
      }
      if ('size' in file) {
        txt += "Size: " + file.size + " bytes <br>";
      }
    }
  }
} 
document.getElementById("demo").innerHTML = txt;

Try It Yourself

Syntax

fileuploadObject.files

Technical Details

Return Value: FileList Object, representing the selected files.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support