写了一个多文件上传(共2M左右),用的是孟子的方法,不过我是一次性出现四个框在本地测试很好,但在服务器上,开始可以用,但用久了就发现会丢失数据,也不出错,本来一次传4张的,结果只能传上一张,不知是什么原因!是不是服务器上要设置什么?webconfig也设置了!

解决方案 »

  1.   

    参考
    http://dotnet.aspx.cc/ShowDetail.aspx?id=6381BD5F-51F3-4339-4239-1328564A1B2A
    后面两段的限制
      

  2.   

    在webconfig中已经设置了!
      <httpRuntime   maxRequestLength="10000000" executionTimeout="3600"/>
      

  3.   

    public  void UpFile(object sender, System.EventArgs e)
    {
    string strsql="select id from Hotel where H_UserID=(select id from UserInfo where U_username='"+Session["username"]+"')";
    try
                {
         bool b=Telecai.cs.Conn.DataReader(strsql);   if(!b)
      {
    Response.Write("<script>alert('您没有发布酒店信息!不能上传图片!');history.go(-1);</script>");
    Response.End();
       }
    }
      catch(Exception en)
    {
     Response.Write("提起数据时出错!");
    }
    StringBuilder Allpath=new StringBuilder();//记录所有的图片路径
     try
     {
    HttpFileCollection file;
    HttpPostedFile pfile;
    file=Request.Files; for(int i=0;i<file.Count;i++)
    {
    pfile=file[i];

    string filename=pfile.FileName;
    if(filename=="")
        {
       fileCount=i;
                       break;
    }
    string type=System.IO.Path.GetExtension(filename);//上传文件类型
    if(type==".JPG"||type==".GIF"||type==".JPEG"||type==".jpg"||type==".gif"||type==".jpeg")
    {
    }
    else
    {
    Response.Write("<script>alert('请确保您上传的第"+(i+1)+"是jpg或者Gif类型!');history.go(-1);</script>");
    Response.End();
    }
    if(pfile.ContentLength>300*1024)
    {
    Response.Write("<script>alert('请确保您上传的第"+(i+1)+"文件不大于300K!');history.go(-1);</script>");
    Response.End();

    }
    }
    if(fileCount==0)
    {
       Response.Write("<script>alert('请选择要上传的图片!');history.go(-1);</script>");
       Response.End();
      
    } for(int i=0;i<fileCount;i++)
    {
    pfile=file[i];
    string filename=pfile.FileName;
    string type=System.IO.Path.GetExtension(filename);//上传文件类型

    string path="/hotel\\"+Session["username"].ToString();
    if(!Directory.Exists(Server.MapPath(path)))//检测目录下是否存在指定的文件夹,没有则以用户名+日期+张数(以0开始计算)创建目录,有则删除后再创建
    {
    Directory.CreateDirectory(Server.MapPath(path));
                     }
    string Upfilename=DateTime.Now.ToShortDateString();
    pfile.SaveAs(HttpContext.Current.Request.MapPath(path)+"\\"+Upfilename+i.ToString()+type);//在数据库中记录图片路径以"|"分开各张

       
       Allpath.Append(path+"\\"+Upfilename+i.ToString()+type);
       Allpath.Append("|");

            
                 }    string sqlstr="update hotel set h_img='"+@Allpath+"' where h_UserID=(select id from UserInfo where u_username='"+Session["username"]+"')";

     int k=Telecai.cs.Conn.DataNonQuery(sqlstr);
     
      
     Response.Write("<script>alert('上传图片成功');history.go(-1);</script>");

    }
    catch(Exception en)
    {
      Response.Write("提起数据时出错!");
    }

    }
      

  4.   

    .net 默认为2M
    但可以在WEBCONFIG或程序中指定
      

  5.   

    楼上的,已经设了啊!
    <httpRuntime   maxRequestLength="10000000" executionTimeout="3600"/>
      

  6.   

    machine.config中设置了吗?注意大小,和超时都要设置
      

  7.   

    确实是machine.config的问题,我把machine.config中的60,改成100就OK了!谢谢各位!