在当前页面如何插入头像。
来源:互联网 发布:下载天猫淘宝商城 编辑:程序博客网 时间:2024/04/28 05:00
if(string.IsNullOrEmpty(FileUpload1.FileName))
{
ClientScript.RegisterStartupScript(this.GetType(),"", "<script>alert('请选择要上传的图片!');</script>");
return;
}
string ImgName =FileUpload1.PostedFile.FileName;
string ImgExtention =System.IO.Path.GetExtension(ImgName);
int ImgSize =FileUpload1.PostedFile.ContentLength;
string newname =DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() +DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() +DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
string ImgPath =Server.MapPath("~/Ftb/");
string ImgUrl ="~/Ftb/" + newname + ImgExtention;
if (ImgExtention !=".gif" && ImgExtention != ".GIF" &&ImgExtention != ".jpg" && ImgExtention != ".JPG"&& ImgExtention != ".jpeg" && ImgExtention !=".JPEG")
{
ClientScript.RegisterStartupScript(this.GetType(), "","<script>alert('图片格式不正确,只支持.gif .jpg .jpeg格式类型的图片!');</script>");
return;
}
//图片尺寸
if (ImgSize / 512000 >= 1)
{
ClientScript.RegisterStartupScript(this.GetType(), "","<script>alert('图片大小不能超过1M!');</script>");
return;
}
//数据添加
//DateTime now =DateTime.Now;
FileUpload1.PostedFile.SaveAs(ImgPath + newname + ImgExtention);
string constr =ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
SqlConnection con = newSqlConnection(constr);
con.Open();
DateTime itime =DateTime.Now;
string str = "insertinto picture(txt,time) values('" + ImgUrl + "','" + itime +"')";//Imgurl就是图片的路径上面定义的
SqlCommand cmd = newSqlCommand(str, con);
int i =cmd.ExecuteNonQuery();
if (i > 0)
{
Response.Write("<script>alert('添加成功')</script>");
}
else
{
Response.Write("<script>alert('添加失败')</script>");
}
con.Close();
- 在当前页面如何插入头像。
- 如何在页面中插入播放器
- wordpress如何获得当前用户的头像
- 在excel中如何快速插入当前日期和时间
- 在emacs中如何快速插入系统当前时间?
- 如何在JSP页面中显示当前时间
- 如何在JSP页面中获取当前系统时间(转)
- 如何在页面上显示当前时间(动态更新)
- SQL---NOW()函数,如何在mysql数据库中插入当前日期,当前时间
- Discuz avatar上传头像,上传完后刷新当前页面
- 求救:如何在asp页面里向数据库插入数据
- 如何在html页面中插入flash透明背景
- Web_如何在页面中插入java applet?
- 如何在aspx页面中插入swf动画
- 如何在PDF中插入另一个PDF文件的页面
- pdf编辑软件如何在pdf中插入页面
- 如何在PDF文件中插入其他PDF页面
- 如何在PDF文件中插入一个空白页面
- 省市县三级联动
- django中遇到的错误及解决方案
- objective-c中的构造函数(对象初始化)(七)
- Sql Server 2005中的架构(Schema)、用户(User)、登录(Login)和角色(Role)
- 13_JavaWeb综合实例
- 在当前页面如何插入头像。
- 内核定时器的使用
- 17-2 运用指针交换了a,b的地址,也就交换了a,b的数值
- Linux 连线跟踪流程整理(linux-2.6.31)
- PHP Comparision Operater
- 个性的桌面电子时钟
- Lua入门 - helloworld
- 《看河南坟头》
- objective-c中对象所有权的内存管理(关于set,get方法),以及如何使用@property来进行简易操作(九)