Posts Tagged ‘javascript to check file size’

I don’t want to post this article as this javascript is using ActiveX object and nowadays in latest browsers it will ask for user permission to access ActiveX object. Sometimes it may happen that browser does not support ActiveX object or it is disabled, at that time this code is of no use.

This code is for those people who are using ActiveX object and knows that browser will defiantly support the below script. May be it is useful to someone like me.

<script language=”javascript” type=”text/javascript”>

    var objFSO ;




        objFSO = new ActiveXObject(“Scripting.FileSystemObject”);








    function CheckExtention(el) // pass Upload File object’s ClientID here



        var myel= document.getElementById(el);

        var file;

        var path = myel.value;


        file = objFSO.getFile(path);

        var size;

        size = file.size ; // This size will be in Bytes

  // We are converting it to KB as below

        alert(‘File Size is : ‘ + file.size /1024 +‘ KB’);