3

Currently I am using

if(navigator.appName=='Microsoft Internet Explorer'){
        if(component.value){
            var oas = new ActiveXObject("Scripting.FileSystemObject");
            var e = oas.getFile(component.value);
            var size = e.size;
        }
    }

to validate the file size.

Is there any other way to validate the size

Automation server can't create object error is displayed

I know it has something to do with Enabling ActiveX Controls in Settings, but thats not going to happen because one cant control client side system and IE7/8 doesnot even support file Api

9
  • 2
    that is so NOT working fine in all browsers but IE... Commented Jun 29, 2013 at 4:57
  • 1
    What ? i checked the code in IE7, IE8... it gives the error Commented Jun 29, 2013 at 5:02
  • 1
    how are you getting the file? Commented Jun 29, 2013 at 5:07
  • 1
    Yea sorry my mistake about that, I had put that code for IE only Commented Jun 29, 2013 at 5:07
  • 1
    Please check the updated question now Commented Jun 29, 2013 at 5:08

3 Answers 3

1

IE doesn't support this feature

I had found a great plugin for file upload jQuery-File-Upload

Sign up to request clarification or add additional context in comments.

2 Comments

well ActiveXObject feature is made specifically for IE
+1 for recommending this plugin, however it does not perform so well in IE 7 regarding file size stuff, it takes a lot of time !!
1

Only IE 9 is not Supporting this Feature.

All Other IE Versions >9 have no Issues.

You can Resolve your issue By applying filter for IE 9 and get file size. use Below code in else condition for other browsers as per Below.

if (browserInfo.indexOf("msie") > -1) 
    {
        /* IE */
        var filepath = document.getElementById('idControl').value;
        if(browserInfo.indexOf("msie 9") == -1)
        {
            var myFSO = new ActiveXObject("Scripting.FileSystemObject");
            if (filepath == "") {
                alert("Please Select File");
                $("#selectorID").attr("src", $("#Contenturlprifix").val() + "/content/img/NoPhoto.png");
                return false;
            }
            file = myFSO.getFile(filepath);
            filetype = document.getElementById('idControl').accept
        }

    } else {
        /* Other */
        file = document.getElementById('idControl').files[0];
        if (file == undefined) {
            alert("Please Select File");
            return false;
        }
        else {
            filetype = file.type;
        }
    }
    if (file != undefined) {
        //10mb size 
        if (file.size / 1024 > 10240) {
            alert("size Exists");
            return false;
        }
        else if (filetype.indexOf('image/') == -1) {
            alert("Select only images");
            return false;
        }
    }

Comments

-1

TRY THIS............

  • Go to internet options.
  • Select security tab.
  • Under Custom level.
  • Ensure that "Initialize and script active x controls is not marked safe for scripting" select the radio button enabled and try to run your code now, I am sure your problem will be solved.

1 Comment

Practically if you are building a web application then you can not ask every customer to do so. Solution should be generic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.