Friday, October 06, 2006

Finding the File Size of Attachment in Javascript

<html>
<head>
<title>Check the Size of a File -- Javascript</title>

<script language="JavaScript">
function CheckFileSize()
{
var objSize = new ActiveXObject("Scripting.FileSystemObject");
var strFileName = objSize.getFile(document.frmFileUpload.strFile.value);
var SizeOfFile = strFileName.size;
alert(SizeOfFile + " bytes");
}
</script>
</head>
<body>
<form name="frmFileUpload">
<input type="file" name="strFile">
<input type="button" name="btnSize" value="Show file size" onClick="CheckFileSize();">
</form>
</body>
</html>


The above code snippet will work only if ActiveX is supported @ the client end.

3 comments:

Anonymous said...

HI Vadivel,

Can't we check d file size by any other means, if we don hav ActiveX on d comp??

- Sesh

karl.tian said...

Hello Vadivel, I want to know if there are any other method to get the file size imformation from client_side before the file is uploaded. Pls give me an introduction.

Anonymous said...

hi Vadivelhos ,I need another method instead of ActiveXControl object.Please let me know the solution.