//判断是否上传图片
if (this.FileUpload_Images.HasFile)
{
try
{
string FileAndExtName = this.FileUpload_Images.FileName; //获取文件名
string ContentType = this.FileUpload_Images.FileName.ToLower();//获取文件类型
string[] ImagesType = ContentType.Split('.');
string SendType = ImagesType[ImagesType.Length - 1].ToString();
int FileSize = this.FileUpload_Images.PostedFile.ContentLength; //获取文件大小
//判断文件类型是否受支持
if (SendType != "jpg" && SendType != "jpeg" && SendType != "gif" && SendType != "png" && SendType != "bmp")
{
JavaScript.Alert("您上传的图片格式不受支持!", this.Page);
return;
}
//判断文件大小
if (FileSize >= 102400)
{
JavaScript.Alert("您上传的文件大小为:" + FileSize + "K!大于100K", this.Page);
return;
}
//生成随机数
Random oRandom = new Random();
string oStringRandom = oRandom.Next(99999999).ToString();
//格式化日期作为文件名
long oStringTime = DateTime.Now.ToFileTimeUtc();
//组合成文件名
string ImageFile = oStringTime + oStringRandom + sz.userID + "." + SendType;
//获取服务器端IP地址
string ServerIP = Request.ServerVariables["LOCAL_ADDR"].ToString();
if (ServerIP == "0.0.0.59")
{
}
else
{
//将图片保存到相应的目录
this.FileUpload_Images.SaveAs(Server.MapPath("~") + "/PhotoImages/" + ImageFile);
}
//获取图片保存地址
sz.sheetPhoto = "~" + "/PhotoImages/" + ImageFile;
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
else
{
//如果未上传图片则为默认图片
sz.sheetPhoto = "~/PhotoImages/no.gif";
}