if (this.FileUpload1.HasFile)
{
if (this.ddlAlbumList.Items.Count != 0)
{
int albumId = int.Parse(this.ddlAlbumList.SelectedValue);
string file = "photos//" + userid + "//" + albumId + "//";
string fillname = this.FileUpload1.PostedFile.FileName.ToLower();
string type = fillname.Substring(fillname.LastIndexOf(".") + 1).ToString();
if (type == "jpeg" || type == "jpg" || type == "gif" || type == "png")
{
int size = Convert.ToInt32(this.FileUpload1.PostedFile.ContentLength) / 1024;
if (size < imgMaxLength)
{
if (!Directory.Exists(Server.MapPath(file)))
{
Directory.CreateDirectory(Server.MapPath(file));
}
try
{
if (type == "jpg")
{
type = "jpeg";
}
string path = file + Guid.NewGuid().ToString();
string url = path + "." + type;
string url2 = path + ".jpg";
this.FileUpload1.SaveAs(this.Server.MapPath(url));
System.Drawing.Image imgoutput1 = Bitmap.FromFile(this.Server.MapPath(url));
int imgWidth = 0;
int gifwidth, gifheight;
if (imgoutput1.Width < imgoutput1.Height)
{
imgWidth = 86;
gifheight = imgWidth;
gifwidth = (int)(double)imgoutput1.Width * imgWidth / imgoutput1.Height;
}
else
{
imgWidth = 96;
gifwidth = imgWidth;
gifheight = (int)(double)imgoutput1.Height * imgWidth / imgoutput1.Width;
}
System.Drawing.Image imgoutput2 = imgoutput1.GetThumbnailImage(gifwidth, gifheight, null, IntPtr.Zero);
imgoutput2.Save(this.Server.MapPath(path + ".jpg"), ImageFormat.Jpeg);
string name = this.txtName.Value.Trim();
string descirption = this.txtDescription.Value.Trim();
DateTime dt = Convert.ToDateTime(System.DateTime.Now);
if (mydb.UploadImage(albumId, name, descirption, url,url2, dt))
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>AlertMsg1('信息提示','上传相片成功!','',260,160);parent.frames('myiframe').document.location.reload()</script>");
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>AlertMsg1('信息提示','上传相片失败!','',260,160);</script>");
}
}
catch
{
return;
}
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>AlertMsg1('信息提示','图片太大,请缩小后上传!','',260,160);</script>");
}
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>AlertMsg1('信息提示','请上传jpg、jpeg、gif、png格式相片!','',260,160);</script>");
}
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>AlertMsg1('信息提示','请创建相册!','',260,160);</script>");
}
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>AlertMsg1('信息提示','请选择上传文件!','',260,160);</script>");
}