• 图片上传


    protected void Upload()
            {
                //判断是否选择文件
                if (FileUpload1.HasFile)
                {
                    string fileContentType = FileUpload1.PostedFile.ContentType;//获取文件类型
                    //判断类型是否符合条件
                    if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg"||fileContentType=="image/PNG")
                    {
                        //客户端文件路径
                        string name = FileUpload1.PostedFile.FileName;
                        FileInfo file = new FileInfo(name);
                        //文件名称
                        string fileName = file.Name;
                        //服务器端文件路径
                        string webFilePath = Server.MapPath("resource/" + fileName);
                        //判断同名文件是否存在
                        if (!File.Exists(webFilePath))
                        {
                            try
                            {
                                //使用SaveAs方法保存文件
                                FileUpload1.SaveAs(webFilePath);
                                this.lMsg.Text = "提示:文件" + fileName + "上传成功!";
                                this.lPathInfo.Text = "resource" + fileName;
                                this.iPic.ImageUrl = "resource" + fileName;
                            }
                            catch (Exception ex)
                            {
                                this.lMsg.Text = "提示:文件上传失败,失败原因:" + ex.Message;
                            }
                        }
                        else
                        {
                            this.lMsg.Text = "提示:文件已经存在,请重命名后上传";
                        }
                    }
                    else
                    {
                        this.lMsg.Text = "提示:文件类型不符合";
                    }
                }
            }
            protected void btUpload_Click(object sender, EventArgs e)
            {
                if (Directory.Exists("resource"))
                {
                    Upload();
                }
                else
                {
                   
                    Directory.CreateDirectory(Server.MapPath("resource"));
                    Upload();
                }
               
            }
  • 相关阅读:
    002STM32+ESP8266+Air302基本控制篇(阿里云物联网平台)STM32+ESP8266使用SSL加密方式接入阿里云物联网平台
    201STM32+ESP8266+Air302基本控制篇(阿里云物联网平台)设备使用一机一密方式连接云平台,并使用物模型Topic上报温湿度数据(STM32+Air302)
    firefox国内版和国际版账号不互通
    linux证书工具
    开发常用在线工具集合
    gcc 编译静态库如果有可能被动态库引用
    [golang]批量修改名称
    fyne关于中文字体的支持【官方回复】
    /usr/bin/ld: warning: z lazyload ignored
    df命令卡死
  • 原文地址:https://www.cnblogs.com/java20130723/p/3211555.html
Copyright © 2020-2023  润新知