我要上传的是视频文件,几百M的视频。
如果写在后台代码里,会先上传,等待半天才进入代码判断。
我想用javasrcipt在选择完文件,就来判断格式,大小。
现在我获得不了input file 的文件大小。
请大家帮忙,感谢大家。
谢谢。

解决方案 »

  1.   

    javascript没有这个能力。在你的asp.net中选择silverlight的上传控件吧。
      

  2.   

    1。 这个不行的  因为是在客户端,获取客户端文件信息 必须修改 IE 安全选项。
    2。 修改安全选项后  下面代码可以实现   (我是赋值到了隐藏控件里 你可以直接判断 进行alert)
    3。 这个是在点击任何按钮之前 选择文件之后进行的  没有点任何上传按钮<input type="file" id="my_file" onchange="SumbitFileAccessInfo();" width="300px" />        function SumbitFileAccessInfo() {
                var filespec = document.getElementById("my_file").value;
                var fso, f, s = new Array();
                try {
                    fso = new ActiveXObject("Scripting.FileSystemObject");
                    f = fso.GetFile(filespec); // filespec 是指定文件的路径(绝对和或相对的),必选项。
                }
                catch (err) {
                    alert('浏览器安全设置出错!');
                    return;
                }
                document.getElementById("creatTime").value = "" + f.DateCreated; //建立时间
                document.getElementById("fSize").value = "" + f.Size; //文件大小
                document.getElementById("fileName").value = "" + f.Path.toUpperCase(); //文件名称
                document.getElementById("lastmodTime").value = "" + f.DateLastModified; //最后修改时间        }
        </script>最大问题就是  必须修改客户端IE 浏览器安全性!!!!
    所以。 
      

  3.   

    我是这样写的,在前台只能判断格式,大小我是在后台判断的。你看看,对你有没帮助~!
    <script>
    function checkType(){   
         
      //得到上传文件的值
        var fileName = document.getElementById("FileUpload1").value;   
      //返回String对象中子字符串最后出现的位置.   
     var seat=fileName.lastIndexOf(".");   
     //返回位于String对象中指定位置的子字符串并转换为小写.   
      var extension=fileName.substring(seat).toLowerCase();   
     //判断允许上传的文件格式        
     var allowed=[".jpg",".gif",".png",".bmp",".jpeg",".txt",".doc",""];   
      for(var i=0;i<allowed.length;i++){   
          if(!(allowed[i]!=extension)){   
             return true;   
          }   
      }   
      alert("不支持"+extension+"格式");   
     return false;   
    }  
    </script>
    后台代码:
     if (FUDotPic.PostedFile.ContentLength < 10485760)
                        {
                            try
                            {
                                //上传文件并指定上传目录的路径(路径可以自己指定)
                                string filepath = Server.MapPath("Upload/table");
                                // Response.Write(filepath);
                                string DateFilePath = DateTime.Now.ToShortDateString();
                                if (!System.IO.Directory.Exists(filepath + "/" + DateFilePath))
                                {
                                    System.IO.Directory.CreateDirectory(filepath + "/" + DateFilePath);
                                }
                                string visualpath = "Upload/table/" + DateFilePath + "/" + Guid.NewGuid().ToString() + FUDotPic.FileName.Substring(FUDotPic.FileName.LastIndexOf("."));
                                string path = Server.MapPath(visualpath);
                                FUDotPic.PostedFile.SaveAs(path);
                                agency.DotPic = path; 
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                        else
                        {
                            throw new Exception("上传文件不能大于10MB");
                        }
      

  4.   

    javasrcipt = JavaScript只使用javascript无法实现这个功能
      

  5.   

    不降低客户ie安全性 只能获取格式   不能获取大小  我之所以我那样写  因为我们客户都必须修改ie听我们的   然后我根本不要他上传文件,因为文件都2G以上   我只要大小  只能那么做所以你还是按7楼做吧