Input FileUpload files attribute

Definition and Usage

files The 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 = " select a 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 += " namesu: " + file.name + "<br>";
      }
      if ('size' in file) {
        txt += " sizesu: " + file.size + " bytes <br>";
      }
    }
  }
} 
document.getElementById ("demo").innerHTML = txt;

亲自试一试

语法

fileuploadObject.files

技术细节

返回值: FileList 对象,代表所选文件。

浏览器支持

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
支持 10.0 支持 支持 支持