Create a gist now

Instantly share code, notes, and snippets.

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
Owner
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