zoukankan      html  css  js  c++  java
  • 实现上传图片

    FileUploadFile 控件

    protected void Button1_Click(object sender, EventArgs e)
        {
            string filePath = "", fileExtName = "", mFileName, mPath;
            if (this.FileUpload1.PostedFile.FileName != "")
            {
                filePath = this.FileUpload1.PostedFile.FileName;
                fileExtName = filePath.Substring(filePath.LastIndexOf(".")+1);
                try
                {
                    mPath = Server.MapPath("upload/");
                    mFileName = filePath.Substring(filePath.LastIndexOf("\\") + 1); //获取文件的文件名
                    this.FileUpload1.PostedFile.SaveAs(mPath + mFileName); //上传路径
                    string sql = "insert into tb_image(image) values ('upload\\" + mFileName + "')"; //写入数据库
                    SqlConnection con = new SqlConnection();
                    SqlCommand cmd = new SqlCommand(con,sql);
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
               catch
                {
                    Response.Write("<script>alert('" + error.ToString() + "')</script>");
                }
            }
        }
    这里没有写数据库连接 ,其实就是获取上传文件的文件名
  • 相关阅读:
    hive表增量抽取到oracle数据库的通用程序(二)
    java进程的守护进程脚本
    hadoop2.7节点的动态增加与删除
    hive表增量抽取到oracle数据库的通用程序(一)
    arduino 驱动电调
    arduino IO口
    通过电机编码器AB相输出确定电机转向
    Wifi小车资料
    winform 按键控制
    vs2010 EF4.0 访问mysql
  • 原文地址:https://www.cnblogs.com/ivy/p/1215829.html
Copyright © 2011-2022 走看看