日期:2014-05-18 浏览次数:20453 次
protected void showUpZp() { try { string imgfilename = ""; if (FileZp.PostedFile.FileName != "") { string fileName = FileZp.PostedFile.FileName; //取得文件名 System.Drawing.Image image = System.Drawing.Image.FromFile(fileName); string strWidth = image.Width.ToString(); string strHeight = image.Height.ToString(); string strDx = string.Format("{0:N2}", Math.Round((Convert.ToDouble(strHeight) / Convert.ToDouble(strWidth)),2)); if (Convert.ToDouble(strDx) <= Convert.ToDouble("1.30")) { if (Convert.ToDouble(strDx) >= Convert.ToDouble("1.20")) { int intFileLength = FileZp.PostedFile.ContentLength; if (intFileLength > 102400) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer='defer'>alert('身份证图片大小不能大于100KB');</script>"); return; } else { string strFullZpName = FileZp.PostedFile.FileName.Substring(FileZp.PostedFile.FileName.IndexOf(".")); imgfilename = txtUserId.Text + "Z" + strFullZpName; FileZp.PostedFile.SaveAs(Server.MapPath("../../UserZp") + "\\" + imgfilename); strFileZpName = imgfilename; } } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer='defer'>alert('头像照片的比例调整为1.2-1.3之间,最佳效果为1.25(即高宽比例为5:4)。');</script>"); } } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer='defer'>alert('头像照片的比例调整为1.2-1.3之间,最佳效果为1.25(即高宽比例为5:4)。');</script>"); } } else { strFileZpName = "UserZp.jpg"; } } catch (System.Exception ex) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer='defer'>alert('身份证图片上传失败:" + ex.Message + "');</script>"); } }