最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

internet explorer - How to get file size from clientside without using activex in javascript? - Stack Overflow

programmeradmin0浏览0评论

Is there any other way to get file size at client side without using ActiveX in IE?

I am getting file size from client side but, IE opens security notification popup for ActiveX controls. Is there any other way to get file size or hide ActiveX popup?

Here is code for getting file size on client side.

<html>
<body>
<form id="file">
<input type="file" id="loadfile" />
<input type="button" value="Image Size" onclick="testSize()" />
</form>
<script type="text/javascript">

function testSize(){
    var browserInfo = navigator.userAgent.toLowerCase();

    if(browserInfo.indexOf("msie") > -1){
        /* IE */
        var filepath = document.getElementById('loadfile').value;
        alert(filepath + " Test ");
        var myFSO = new ActiveXObject("Scripting.FileSystemObject");
        var thefile = myFSO.getFile(filepath);
        var imgbytes = thefile.size;
        alert( "name " +  thefile.name + "Size " +  thefile.size );
    }else{
        /* Other */
        var file = document.getElementById('loadfile').files[0];
        alert( "name " +  file.name + "Size " +  file.size );
    }
}
</script>
</body>
</html>

Thanks in advance.

Is there any other way to get file size at client side without using ActiveX in IE?

I am getting file size from client side but, IE opens security notification popup for ActiveX controls. Is there any other way to get file size or hide ActiveX popup?

Here is code for getting file size on client side.

<html>
<body>
<form id="file">
<input type="file" id="loadfile" />
<input type="button" value="Image Size" onclick="testSize()" />
</form>
<script type="text/javascript">

function testSize(){
    var browserInfo = navigator.userAgent.toLowerCase();

    if(browserInfo.indexOf("msie") > -1){
        /* IE */
        var filepath = document.getElementById('loadfile').value;
        alert(filepath + " Test ");
        var myFSO = new ActiveXObject("Scripting.FileSystemObject");
        var thefile = myFSO.getFile(filepath);
        var imgbytes = thefile.size;
        alert( "name " +  thefile.name + "Size " +  thefile.size );
    }else{
        /* Other */
        var file = document.getElementById('loadfile').files[0];
        alert( "name " +  file.name + "Size " +  file.size );
    }
}
</script>
</body>
</html>

Thanks in advance.

Share asked Jun 6, 2012 at 9:31 Dipesh GandhiDipesh Gandhi 7651 gold badge13 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

I got solution.

There is no geniune problem with the code the problem is with internet explorer browser security settings. Generally you face this type of error when you want to open a text file or some excel files on a remote server

go to internetoptions < security < customlevel < initialize and script active x controls not marked safe for scripting and mark them enabled and i think your problem will be removed

thanks.

发布评论

评论列表(0)

  1. 暂无评论