zoukankan      html  css  js  c++  java
  • .NET上传单张图片代码

    //上传图片
            protected void Button4_Click(object sender, EventArgs e)
            
    {
               Random rad 
    = new Random();
               
    string pathname = Server.MapPath("img/");//要保存到的文件夹
                string filename = FileUpload1.FileName;//选中的图片名
                string filepath = DateTime.Now.Millisecond + rad.Next().ToString() + filename;//要保存的图片名

                
    int filesize = FileUpload1.PostedFile.ContentLength;//图片大小
                string filetype = filename.Substring(filename.LastIndexOf("."+ 1);//图片后缀

                
    if ((filetype == "jpg" || filetype == "jpeg" || filetype == "gif"))
                
    {
                    
    //文件大小要小于200k
                    if (filesize < 200000)
                    
    {
                        FileUpload1.PostedFile.SaveAs(Server.MapPath(
    "~/img/"+ filepath);
                        Image1.ImageUrl 
    = "~/img/" + filepath; //用image控件显示一下图
                        TextBox7.Text = "~/img/" + filepath; //把图片地址保存到图片地址框中
                    }

                    
    else
                    
    {
                        TextBox7.Text 
    = "图片超过100K了!";
                    }

                }

                
    else
                
    {
                    TextBox7.Text 
    = "不能上传这种格式的图片!";
                }

                TextBox8.Focus();
    //聚焦到下一个输入框
            }
  • 相关阅读:
    CF 1182F Maximum Sine——根号算法
    左偏树学习笔记
    CF1182 D Complete Mirror——思路
    AT3576 E Popping Balls——计数思路
    loj 6053 简单的函数 —— min_25筛
    bzoj 2784 时间流逝 —— 树上高斯消元
    loj 2542 随机游走 —— 最值反演+树上期望DP+fmt
    poj 2096 , zoj 3329 , hdu 4035 —— 期望DP
    loj 6485 LJJ学二项式定理 —— 单位根反演
    bzoj 3328 PYXFIB —— 单位根反演
  • 原文地址:https://www.cnblogs.com/kingfly/p/1572780.html
Copyright © 2011-2022 走看看