多文件上传,有时通过,有时不通过! 写了一个多文件上传(共2M左右),用的是孟子的方法,不过我是一次性出现四个框在本地测试很好,但在服务器上,开始可以用,但用久了就发现会丢失数据,也不出错,本来一次传4张的,结果只能传上一张,不知是什么原因!是不是服务器上要设置什么?webconfig也设置了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考http://dotnet.aspx.cc/ShowDetail.aspx?id=6381BD5F-51F3-4339-4239-1328564A1B2A后面两段的限制 在webconfig中已经设置了! <httpRuntime maxRequestLength="10000000" executionTimeout="3600"/> 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("提起数据时出错!"); } } .net 默认为2M但可以在WEBCONFIG或程序中指定 楼上的,已经设了啊!<httpRuntime maxRequestLength="10000000" executionTimeout="3600"/> machine.config中设置了吗?注意大小,和超时都要设置 确实是machine.config的问题,我把machine.config中的60,改成100就OK了!谢谢各位! 问一个GridView根据Listbox改变数据源的问题 .net想做一个后台自动发送邮件功能,邮件的格式我想做成个模版 关于压缩文件夹问题 笑吧,笑吧,我认了,新手提问三 技术部KPI考核标准有哪些,进来都有分拿 帮帮忙asp.net后台访问iframe问题 登录按钮代码错误 gridview控件怎样改变其默认显示行数? 如何在VSNET开发环境下,运用命名空间建立项目 验证字符串问题 如果连接字符串密码错误,是不是不会有异常啊 请问关于gridview中删除的问题
http://dotnet.aspx.cc/ShowDetail.aspx?id=6381BD5F-51F3-4339-4239-1328564A1B2A
后面两段的限制
<httpRuntime maxRequestLength="10000000" executionTimeout="3600"/>
{
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("提起数据时出错!");
}
}
但可以在WEBCONFIG或程序中指定
<httpRuntime maxRequestLength="10000000" executionTimeout="3600"/>