多文件上传,有时通过,有时不通过!

oldmoon 2006-04-29 03:53:21
写了一个多文件上传(共2M左右),用的是孟子的方法,不过我是一次性出现四个框在本地测试很好,但在服务器上,开始可以用,但用久了就发现会丢失数据,也不出错,本来一次传4张的,结果只能传上一张,不知是什么原因!是不是服务器上要设置什么?webconfig也设置了!
...全文
329 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
oldmoon 2006-05-05
  • 打赏
  • 举报
回复
确实是machine.config的问题,我把machine.config中的60,改成100就OK了!谢谢各位!
newline2000 2006-05-01
  • 打赏
  • 举报
回复
machine.config中设置了吗?注意大小,和超时都要设置
webwalker 2006-04-30
  • 打赏
  • 举报
回复
webconfig
webwait 2006-04-29
  • 打赏
  • 举报
回复
mark
return_more 2006-04-29
  • 打赏
  • 举报
回复
帮不上忙……
oldmoon 2006-04-29
  • 打赏
  • 举报
回复
顶一把
njuzgj 2006-04-29
  • 打赏
  • 举报
回复
关注
oldmoon 2006-04-29
  • 打赏
  • 举报
回复
服务器有时候接收到一张,有时候三张,不知是怎么样回事!都不会出错误!怪事!
oldmoon 2006-04-29
  • 打赏
  • 举报
回复
一共传四张,规定每张不得大于300K,一共也只有1.2M,测试发现只能传三张,传到第四张就不行了,也不出错误,选择传四张的话,服务器也只能收到三张!郁闷!
oldmoon 2006-04-29
  • 打赏
  • 举报
回复
楼上的,已经设了啊!
<httpRuntime maxRequestLength="10000000" executionTimeout="3600"/>
huangkc 2006-04-29
  • 打赏
  • 举报
回复
.net 默认为2M
但可以在WEBCONFIG或程序中指定
oldmoon 2006-04-29
  • 打赏
  • 举报
回复
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("提起数据时出错!");
}

}
oldmoon 2006-04-29
  • 打赏
  • 举报
回复
在webconfig中已经设置了!
<httpRuntime maxRequestLength="10000000" executionTimeout="3600"/>
oldmoon 2006-04-29
  • 打赏
  • 举报
回复
孟老大,共2M左右啊,服务器上要怎么设置的啊!
孟子E章 2006-04-29
  • 打赏
  • 举报
回复
参考
http://dotnet.aspx.cc/ShowDetail.aspx?id=6381BD5F-51F3-4339-4239-1328564A1B2A
后面两段的限制
孟子E章 2006-04-29
  • 打赏
  • 举报
回复
看看你上传的文件总共的大小,一般默认下服务器有大小限制

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧