W3cubDocs

/DOM

File.name

Returns the name of the file represented by a File object. For security reasons, the path is excluded from this property.

Syntax

var name = file.name;

Value

A string, containing the name of the file without path, such as "My Resume.rtf".

Example

<input type="file" multiple onchange="processSelectedFiles(this)">
function processSelectedFiles(fileInput) {
  var files = fileInput.files;

  for (var i = 0; i < files.length; i++) {
    alert("Filename " + files[i].name);
  }
}

Try the results out below:

Specifications

Specification Status Comment
File API
The definition of 'name' in that specification.
Working Draft Initial definition.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 13 12 3.6 10 16 Yes
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes Yes No No No Yes

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/File/name