protected void btnUpload_Click(object sender, EventArgs e)
{ {
HttpFileCollection files = HttpContext.Current.Request.Files;
System.Text.StringBuilder strmsg = new System.Text.StringBuilder(""); //这句是什么用啊
string[] rd = Request.Form[1].Split(',');//这句是什么用啊
int ifile;
for (ifile = 0; ifile < files.Count; ifile++)
{
if (files[ifile].FileName.Length > 0)
{
System.Web.HttpPostedFile postedfile = files[ifile];
if (postedfile.ContentLength / 1024 > 1024)
{
strmsg.Append(Path.GetFileName(postedfile.FileName) + "---不能大于1024k<br>");
break;
}
string fex = Path.GetExtension(postedfile.FileName);
if (fex != ".jpg" && fex != ".JPG" && fex != ".gif" && fex != ".GIF")
{
strmsg.Append(Path.GetFileName(postedfile.FileName) + "---图片格式不对,只能是jpg或gif<br>");
break;
}
}
}
if (strmsg.Length <= 0)//这句就不懂为什么?
{
string dirpath = Server.MapPath("51aspx"); if (Directory.Exists(dirpath) == false)
{
Directory.CreateDirectory(dirpath);
}
Random ro = new Random();
int name = 1;
for (int i = 0; i < files.Count; i++)
{
System.Web.HttpPostedFile myFile = files[i];
string FileName = "";
string FileExtention = "";
FileName = System.IO.Path.GetFileName(myFile.FileName);
string stro = ro.Next(100, 100000000).ToString() + name.ToString();
string NewName = DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + stro;
if (FileName.Length > 0) {
FileExtention = System.IO.Path.GetExtension(myFile.FileName); string ppath = dirpath + @"\" + NewName + FileExtention;
myFile.SaveAs(ppath); } name = name + 1; } Response.Write("<script>alert('恭喜,图片上传成功!')</script>");
}
else
{
lblMessage.Text = strmsg.ToString();
lblMessage.Visible = true;
}
} }
{ {
HttpFileCollection files = HttpContext.Current.Request.Files;
System.Text.StringBuilder strmsg = new System.Text.StringBuilder(""); //这句是什么用啊
string[] rd = Request.Form[1].Split(',');//这句是什么用啊
int ifile;
for (ifile = 0; ifile < files.Count; ifile++)
{
if (files[ifile].FileName.Length > 0)
{
System.Web.HttpPostedFile postedfile = files[ifile];
if (postedfile.ContentLength / 1024 > 1024)
{
strmsg.Append(Path.GetFileName(postedfile.FileName) + "---不能大于1024k<br>");
break;
}
string fex = Path.GetExtension(postedfile.FileName);
if (fex != ".jpg" && fex != ".JPG" && fex != ".gif" && fex != ".GIF")
{
strmsg.Append(Path.GetFileName(postedfile.FileName) + "---图片格式不对,只能是jpg或gif<br>");
break;
}
}
}
if (strmsg.Length <= 0)//这句就不懂为什么?
{
string dirpath = Server.MapPath("51aspx"); if (Directory.Exists(dirpath) == false)
{
Directory.CreateDirectory(dirpath);
}
Random ro = new Random();
int name = 1;
for (int i = 0; i < files.Count; i++)
{
System.Web.HttpPostedFile myFile = files[i];
string FileName = "";
string FileExtention = "";
FileName = System.IO.Path.GetFileName(myFile.FileName);
string stro = ro.Next(100, 100000000).ToString() + name.ToString();
string NewName = DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + stro;
if (FileName.Length > 0) {
FileExtention = System.IO.Path.GetExtension(myFile.FileName); string ppath = dirpath + @"\" + NewName + FileExtention;
myFile.SaveAs(ppath); } name = name + 1; } Response.Write("<script>alert('恭喜,图片上传成功!')</script>");
}
else
{
lblMessage.Text = strmsg.ToString();
lblMessage.Visible = true;
}
} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货