zoukankan      html  css  js  c++  java
  • Asp.Net图片上传

    <div>

                            <asp:FileUpload ID="FileUpload1" runat="server" Height="25px"/>
                            <asp:ImageButton runat="server" ID="btn_Upload" ImageUrl="~/Activity/images/upload.gif"
                                Style="margin-bottom: -8px;" OnClick="btn_Upload_Click" /><br />
                            <asp:Image ID="imgUrl" runat="server" Visible="false" /></div> 

    protected void btn_Upload_Click(object sender, ImageClickEventArgs e)
            {
                string path = "/uploadfiles/Activity/";
                string folderPathforsave = Server.MapPath(path);
                if (!Directory.Exists(folderPathforsave))
                {
                    Directory.CreateDirectory(folderPathforsave);
                }

                string filename = FileUpload1.FileName;

                if (filename != "")
                {
                    filename = filename.Substring(filename.LastIndexOf("."));
                    if (filename.ToLower() == ".jpg" || filename.ToLower() == ".bmp" || filename.ToLower() == ".gif")
                    {
                        string strpic = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now)+filename;
                        fup_Act_Image.SaveAs(folderPathforsave + strpic);
                        path += strpic;
                        imgUrl.Visible = true;
                        imgUrl.ImageUrl = path;
                    }
                    else
                    {
                        MsgBox.MsgBoxShow(this.Page, "支持jpg,bmp,gif等上传文件格式!");
                        return;
                    }
                }
            }

  • 相关阅读:
    Ajax基础知识详解
    php 基础语法整理
    06 js-递归
    原生js 实现瀑布流布局
    解决高度坍塌问题
    jQuery动画效果
    jQuery增删元素类名
    JQueryTab栏切换(important!)
    jQuery排他思想(important!)
    jQuery设置元素样式
  • 原文地址:https://www.cnblogs.com/Bright/p/2232023.html
Copyright © 2011-2022 走看看