2013-06-29 46 views
3

目前我使用如何在客户端使用IE 7/8中的javascript验证文件大小?

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; 
     } 
    } 

验证文件的大小。

是否有任何其他的方式来验证大小

Automation server can't create object error is displayed 

我知道它是与启用ActiveX控件在设置的控制,但是那不会发生,因为一个无法控制客户端系统和IE7/8甚至不列入支持文件阿比

+2

这是如此不工作在所有浏览器,但IE浏览器... – dandavis

+1

什么?我检查了IE7中的代码,IE8 ...它给出了错误 –

+1

你怎么得到这个文件? – dandavis

回答

-1

试试这个............

  • 进入internet选项。
  • 选择安全选项卡。
  • 在自定义级别下。
  • 确保“Initialize and script active x controls are not marked safe for scripting”选择已启用的单选按钮并尝试立即运行您的代码,我相信您的问题将得到解决。
+5

实际上,如果您正在构建Web应用程序,那么您不能要求每个客户这样做。解决方案应是通用的。 – shaILU

1

IE浏览器不支持此功能

我已经找到了文件一个伟大的插件上传jQuery-File-Upload

+2

well ActiveXObject功能是专门为IE –

+0

+1推荐的这个插件,但是在IE 7中关于文件大小的东西表现不好,需要很多时间! –

0

只有IE 9不支持此功能。

所有其他IE版本> 9没有问题。

您可以解决您的问题通过对IE 9应用过滤器并获取文件大小。 使用其他浏览器的其他条件下面的代码按照下面。

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; 
     } 
    } 
相关问题