How to get file Information like name, size, type and modified date in JavaScript

Information like, Javascript, URL Parameters

It is good idea to apply client side validation to make form or file validation sudden, Information like Always reach validate file opinion in the back sending to remove taking into consideration if user upload some file, apply client side validation as regards file type, size which in the future happening user to upload definite file on the subject of the order of server, Following are the single descent of code is JavaScript to get sticking to of proclaim, size, type and last modified date of selected files.

Get File Name in JavaScript

var fileName = document.getElementById('file').files[0].name;
console.log(fileName);
alert(fileName);

Get File Type in JavaScript

var fileType = document.getElementById('file').files[0].type;
console.log(fileType);
alert(fileType);

Get File Size in JavaScript

var fileSize = document.getElementById('file').files[0].size;
console.log(fileSize);
alert(fileSize);

Get File Lst Modified Date in JavaScript

var fileLastModifiedDate = document.getElementById('file').files[0].lastModifiedDate;
console.log(fileLastModifiedDate);
alert(fileLastModifiedDate);

Using above take leisure motion you can easily make custom JavaScript take leisure doings-engagement-conflict to obtain every one the file details in array

function getFileInfo(){
    var fileInfo = new array();
        fileInfo['fileName'] = document.getElementById('file').files[0].name;
        fileInfo['fileSize'] = document.getElementById('file').files[0].size;
        fileInfo['fileType'] = document.getElementById('file').files[0].type;
        fileInfo['fileModifiedDate'] = document.getElementById('file').files[0].lastModifiedDate;
        console.log(fileInfo);
}

Leave a Reply