Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Input FileUpload files Property
The HTML DOM FileUpload files property returns a FileList object which contains all the files that are selected by the file upload button.
Syntax
Following is the syntax −
object.files
Example
Let us see an example of FileUpload files property −
<!DOCTYPE html>
<html>
<head>
<style>
body{
text-align:center;
background-color:#52B2CF;
color:#fff;
}
.btn{
background-color:coral;
border:none;
height:2rem;
border-radius:50px;
width:60%;
margin:1rem auto;
display:block;
color:#fff;
outline:none;
}
.show{
font-size:1.2rem;
color:#fff;
font-weight:bold;
}
</style>
</head>
<body>
<h1>DOM FileUpload files Property Example</h1>
<p>Select some files</p>
<input type="file" class="file-upload-btn" multiple>
<button onclick = "showFiles()" class = "btn">Click me to see all selected file</button>
<div class="show"></div>
<script>
function showFiles() {
var fileBtn = document.querySelector(".file-upload-btn");
var showMsg = document.querySelector(".show");
showMsg.innerHTML='';
if(fileBtn.files.length === 0){
showMsg.innerHTML = "Please select at least one file!!";
} else {
showMsg.innerHTML = "You selected these files:";
for(let i=0;i<fileBtn.files.length;i++) {
showMsg.innerHTML += '<p>' + fileBtn.files[i].name + '<p>';
}
}
}
</script>
</body>
</html>
Output
This will produce the following output −

Click on “Click me to see all selected file” button to display all the selected files.

Advertisements