如何从客户端获取文件大小而不使用JavaScript中的ActiveX? [英] How to get file size from clientside without using activex in javascript?

查看:137
本文介绍了如何从客户端获取文件大小而不使用JavaScript中的ActiveX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IE ? ActiveX 还有没有其他方法可以在客户端获得文件大小? >

我从客户端获取文件大小,但是,IE打开ActiveX控件的安全通知弹出窗口。有没有其他的方式来获取文件大小或隐藏的ActiveX弹出?

这是获取文件大小在客户端的代码

 < html> 
< body>
< form id =file>
< input type =fileid =loadfile/>
< input type =buttonvalue =Image Sizeonclick =testSize()/>
< / form>
< script type =text / javascript>

function testSize(){
var browserInfo = navigator.userAgent.toLowerCase();
$ b $ 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 {
/ *其他* /
var file = document.getElementById('loadfile')。files [0];
alert(name+ file.name +Size+ file.size);
}
}
< / script>
< / body>
< / html>

提前致谢。

方案

我得到了解决方案。



这个代码没有geniune问题,IE浏览器的安全设置是这个问题。
通常当你想在远程服务器上打开一个文本文件或一些excel文件时,你会遇到这种类型的错误



转到internetoptions<安全性customlevel<初始化和脚本激活x控件不标记为安全的脚本,并将其标记为启用,我认为你的问题将被删除



谢谢。


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.

解决方案

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.

这篇关于如何从客户端获取文件大小而不使用JavaScript中的ActiveX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆