Get file size of file in file input control.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file: file input control e.g. $("#file")[0] | |
function getFileSize(file) | |
{ | |
if (0 === file.value.length) | |
return 0; | |
// Non-IE browsers | |
if (file.files) | |
{ | |
if (file.files.length > 0) | |
return Math.floor(file.files[0].size / 1024); // size in KB | |
else | |
return 0; | |
} | |
else // IE | |
{ | |
try | |
{ | |
var fso = new ActiveXObject("Scripting.FileSystemObject"); | |
var fo = fso.getFile(file.value); | |
return Math.floor(fo.size / 1024); // size in KB | |
} | |
catch (e) | |
{ | |
// ActiveX must be enabled in your IE browser. | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
go to internetoptions < security < customlevel < initialize and script active x controls not marked safe for scripting and mark them enabled