zoukankan      html  css  js  c++  java
  • asp.net图片上传


    代码
    protected void Button1_Click(object sender, EventArgs e)
        {
            
    string FilePath = Server.MapPath("./"+ "File";//将要存放的路径文件File;
            string newName;    
            
    string picExt;
            
    if (FileUpload1.HasFile)
            {
    //判断选择了文件

                HttpPostedFile HPF 
    = FileUpload1.PostedFile;
                
    // 这种方法用单个文件上传,多个文件要用HttpFileCollection

                
    if (HPF.ContentLength > 0)
                {
    //判断文件大小              
                    picExt = System.IO.Path.GetExtension(HPF.FileName).ToLower();//获得文件的拓展     
                    newName = DateTime.Now.ToString("yyyyMMddHHmmss");
                    newName 
    += picExt;
                    
    if (picExt==".jpg"||picExt==".bmp"||picExt==".png"||picExt==".gif")
                    {
                        
    // HPF.SaveAs(FilePath + "\\" + System.IO.Path.GetFileName(HPF.FileName));HPF.FileName这个是获取文件的名字
                        HPF.SaveAs(FilePath + "\\" + System.IO.Path.GetFileName(newName));
                    }
                    
    else
                    {
                        
    this.Label1.Text = "图片格式不支持,请选择jpg|png|gif|bmp格式";
                    }
                 
                }
                      
            }
            
    else
            {
                Label1.Text 
    = "请选择图片";        
            }
            
        }
     
  • 相关阅读:
    设置nginx中文件上传的大小限制度
    百度编辑器(ueditor)踩坑,图片转存无法使用
    帝国cms更换Ueditor编辑器上传图片加水印
    帝国cms7.5整合百度编辑器ueditor教程
    帝国CMS万能标签ecmsinfo介绍
    帝国CMS排行榜调用标签
    通过案例理解position:relative和position:absolute
    帝国CMS万能标签标题截取后自动加入省略号
    linux 安装字体
    Ecms7.5版CK编辑器保留word格式如何修改
  • 原文地址:https://www.cnblogs.com/clc2008/p/1613411.html
Copyright © 2011-2022 走看看