Skip to content

Instantly share code, notes, and snippets.

@tiendq
Created August 14, 2012 10:03
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tiendq/3347948 to your computer and use it in GitHub Desktop.
Get file size of file in file input control.
// 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;
}
}
}
@tiendq
Copy link
Author

tiendq commented Aug 14, 2012

go to internetoptions < security < customlevel < initialize and script active x controls not marked safe for scripting and mark them enabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment