现在的位置: 首页 > 综合 > 正文

NeatUpload js 判断上传文件的大小是否超过了空间的大小

2013年04月06日 ⁄ 综合 ⁄ 共 2327字 ⁄ 字号 评论关闭

1.NeatUpload 的用法就不说了,搜索一下很多,配置下Web.config

  <httpModules>
       
<add name="UploadHttpModule" type="Brettle.Web.NeatUpload.UploadHttpModule, Brettle.Web.NeatUpload"/>
</httpModules>

  <httpRuntime executionTimeout="600" maxRequestLength="10485760" useFullyQualifiedRedirectUrl="false"/>

2.由于配置了上传文件的大小,前台上传的页面会产生大量的js文件,由于其中的

js中的一个文件WebForm_OnSubmit 函数导致 自定义的js验证函数无效,需要重写下这个函数,这个函数要放在页面中生成的WebForm_OnSubmit 的下面,不然,重写的也是无效的,不起什么作用

3.<script>

  function ToggleVisibility(id, type)
        {
          el = document.getElementById(id);
         
if(el.style)
             {
               
if(type == 'on')
                 {
                     el.style.display
= 'block';
                 }
                
else
                 {
                     el.style.display
= 'none';
                 }
             }
            
else
             {
               
if(type == 'on')
                {
                     el.display
= 'block';
                }
               
else
                {
                     el.display
= 'none';
                }
             }
        }
</script>

<form id="form1" runat="server">

<upload:InputFile id="AttachFile" runat="server"></upload:InputFile>
      
<asp:Button ID="Upload" runat="server" Text="上传"   OnClientClick="ToggleVisibility('ProgressBar','on')" OnClick="Upload_Click"/>
        
<div id="ProgressBar"   style="display:none; width:auto;">
           
<upload:progressbar id="pbProgressBar" runat="server" Inline="true" Width="500px" Height="35px" Triggers="Upload"> </upload:progressbar>
           
</div>

  <script>function WebForm_OnSubmit {

 var tmpspace=0;//如果为1则说明空间不足,无法上传

 var xmlhttp=new ActiveXObject("MSXML2.xmlHttp");

if(xmlhttp!=null)

{

  var filepath=document.getElementById("AttachFile").value;//获取上传文件的路径

 var url="Test.aspx?ID="+spaceID+"&filepath="+escape(filepath);

  xmlhttp.open("POST",url,false);

 xmlhttp.onreadystatechange=function(){

 if(xmlhttp.readystate==4)

{  tmpspace=xmlhttp.responseText;

}

xmlhttp.send("");

}

 if(tmpspace==1)

  {

    alert("空间不足,不能上传");

   return false;

  }

NeatUpLoad_OnSubmitForm_aspnetForm();

return ture;

}

}

</script>

</form>

4.Test.aspx

   using System.IO;

    int ID=int.parse(Request.QueryString("ID"));

     //根据这个ID 计算空间的大小

   string filepath=Request.QueryString("filepath");

  FileInfo fn=new FileInfo(filepath);

  long filesize=fn.length;

   .................................

  然后根据空间的大小和文件大小比较,是否可以上传 (自己定义:如果可以上传则为0 不可以上传则为1)

Response.Clear(); 

Response.Write("1");//不可以上传

Response.End();

抱歉!评论已关闭.