0

I've an application where I need to check file size whether it is less than or equal to 1MB. For that I am writing a javascript function given as below--

function getFileSize1()
{ 
 var myFSO = new ActiveXObject("Scripting.FileSystemObject");
 var filepath = document.form1.attachment.value;
 var error="";

 if(filepath=="")
    return error;
 else
{
    var selectedfile = myFSO.getFile(filepath);
    var size = selectedfile.size;


    if(size >= 1048576)
    {
        error="File size of First Attachment should be less than or Equal to 1 MB \n";
    }
    return error;
}
}

The above code runs in IE6, But it doesn't work with IE9, Mozila latest version and Chome. Can anybody tell what to do to run the above code in all browser?

atabrizi
  • 908
  • 1
  • 13
  • 29
user1407310
  • 173
  • 4
  • 4
  • 9
  • ActiveX works for some versions of IE only! and JS usually doesn't allows any other mechanism of file handling to check file size; You need to try something else. SEE http://stackoverflow.com/q/3717793/570897 – Vishal Sep 24 '12 at 07:28

1 Answers1

2

Activex is supported only in IE and not other browsers, may be you might need to check a similar thread

ActiveXObject in Firefox or Chrome (not IE!)

Community
  • 1
  • 1
  • Can u kindly provide me the code which will run in all browser? – user1407310 Sep 24 '12 at 07:29
  • ok the simplest way is to use a flash plugin, where it is cross browser and will also expose few methods of the file attribute like size etc. you can try http://code.google.com/p/swfupload/ , i havent tried it though. – Chandra Sekhar Walajapet Sep 24 '12 at 08:04