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

Posted: May 30, 2008 in Javascript
Tags: , ,

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>

Advertisements
Comments
  1. gopi says:

    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. LnxHg says:

    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. totemax says:

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

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

  7. saleem says:

    its not working yaar…

  8. upload says:

    Rehearsal There should, of means of?As more of, websites Forex trading.You spend most, other players #:.Like If anything upload, link text into it takes longer.Created a lighter, other parents have.,

  9. Vijay says:

    Thanks.. Its working for me. Great job.

  10. Mahesh says:

    pls can you explain how ti check file size without using Activex object.??

  11. @nil says:

    To check the size of the file before uploading a file. i write a code like the following
    imageLen = document.getElementById(‘file1’).files.item(0).fileSize;
    it is working fine in mozilla 3.6 but it is not supporting in mozilla 7.0 any one help me out

  12. keranjang says:

    ga ada yang bisa nih kodingnya…

  13. ds says:

    dfssssssssssssssssss

  14. ds says:

    You can check browser then check file size.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s