这个代码在asp.net怎么写!!
2个回答
展开全部
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileleixing = System.IO.Path.GetExtension(FileUpload1.FileName).ToString();
if (fileleixing == ".gif" || fileleixing == ".jpg" || fileleixing == ".bmp")
{
string picName = FileUpload1.FileName;
string serverPath = Server.MapPath("../Images/images");
if (!System.IO.Directory.Exists(serverPath))
{
System.IO.Directory.CreateDirectory(serverPath);
}
string imgName = FileUpload1.FileName;
string newPath = serverPath + "\\" + imgName;
int fileLenth = FileUpload1.PostedFile.ContentLength / 1024;
if (fileLenth < 500)
{
FileUpload1.PostedFile.SaveAs(newPath);
this.lblMes.Text = "上传成功!";
this.imgPic.ImageUrl = "../Images/images/" + picName;
}
else
{
Response.Write("<script>alert('图片大小不能大于500KB!');</script>");
}
}
else
{
Response.Write("<script>alert('请选择图片类型文件上传!');</script>");
}
}
else
{
Response.Write("<script>alert('请选择要上传的图片!');</script>");
}
}
限制500k,图片格式你自己改下就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询