How to get file size from clients using javascript in IE?
I used the following method
HTML
<input type="file" id="loadfile" /> Javascript
var file = document.getElementById('loadfile').files[0]; alert( "name " + file.name + "Size " + file.size ); It works great with other browsers except IE :( How to get into IE?
IE does not provide file size information. I'm afraid. You can use the HTML5 file API with IE10, see here: -
Javascript to check file size before uploading to Internet Explorer
you can do it like this using activeX
function getSize() { var myFSO = new ActiveXObject("Scripting.FileSystemObject"); var filepath = document.upload.file.value; var thefile = myFSO.getFile(filepath); var size = thefile.size; alert(size + " bytes"); } see here for more details;
how to check file size using HTML and Javascript on the client side
document.getElementById('loadfile').addEventListener('change', checkFile, false); function checkFile(e) { var file_list = e.target.files; for (var i = 0, file; file = file_list[i]; i++) { var fileExtension = file.name.split('.')[file.name.split('.').length - 1].toLowerCase(); var iConvert = (file.size / 1024).toFixed(2); txt = "File type : " +fileExtension + "\n"; if(file.size > (1024 * 1024)){ txt += "Size: " + (file.size / (1024*1024)).toFixed(2) + " MB \n"; } else { txt += "Size: " + (file.size / 1024).toFixed(2) + " KB \n"; } alert(txt); } } see filddle
IE prior to version 9 does not support the API file , which is required to get the file size. IE10 does not support file size.
IE does not support file APIs
source: https://github.com/blueimp/jQuery-File-Upload/issues/147
You must use an ActiveX control to complete this action.
function getSize() { var myFSO = new ActiveXObject("Scripting.FileSystemObject"); var filepath = document.upload.file.value; var thefile = myFSO.getFile(filepath); var size = thefile.size; alert(size + " bytes"); }