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)"> <div id="output"></div>
const output = document.querySelector("#output"); function processSelectedFiles(fileInput) { let files = fileInput.files; output.textContent = "List of Selected Files:"; for (let i = 0; i < files.length; i++) { output.textContent += `\nFilename: ${files[i].name}`; } }
Result
Specifications
Specification |
---|
File API # dfn-name |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
name |
13 |
12 |
3.6 |
10 |
16 |
7 |
≤37 |
Yes |
4 |
No |
7 |
Yes |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/File/name