Using javascript check uploaded file size, which is uploaded by a file upload control

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 ;

 

    try

    {

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

    }

    catch(err)

    {

        alert(err.message);

        alert(err.number);

    }

 

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

    {

 

        var myel= document.getElementById(el);

        var file;

        var path = myel.value;

        //alert(path);

        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’);

    }

 

</script>

6 Responses to “Using javascript check uploaded file size, which is uploaded by a file upload control”

  1. what about firefox ie it will not work in firefox,safari,opera….

  2. ashish bhatt Says:

    I want to know about the uploading file and getting the particular file extension.

  3. Zbigniew Says:

    When i run this script I’ve got a err no -2146827859 ” Does someone knew why ?

  4. I´m looking for the standard for all navegators

  5. this script does not work in safari, firefox, and others, except IE… damn it.!

  6. if you want it with firefox it’s very simply:

    fileupload = document.getElementById(‘myfile’);
    if(fileupload.files)
    {
    var size = fileupload.files.item(0).fileSize;
    }

Leave a Reply