zoukankan      html  css  js  c++  java
  • FileUpLoad控件

    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Image ID="Image" runat="server" width="50" Height="50"/>
            <br />
            <asp:TextBox ID="info" runat="server"></asp:TextBox>
            <br />
     
            <asp:FileUpload ID="up" runat="server" />
            <br/>
            <asp:Button ID="btnupLoad" runat="server" Text="Button" 
                onclick="btnupLoad_Click" />
        </div>
        </form>
    </body>
    </html>

    后套代码:

    protected void btnupLoad_Click(object sender, EventArgs e)
        {
            if (up.HasFile)
            {
                if (up.PostedFile.ContentType.Substring(0, 5) == "image")
                {
                    try
                    {
                        string serverPath = Server.MapPath("upLoad");
                        if (!System.IO.Directory.Exists(serverPath))
                        {
                            System.IO.Directory.CreateDirectory(serverPath);
                        }
                        string imgName = up.FileName;
                        string newPath = serverPath + "\" + imgName;
                        up.SaveAs(newPath);
                        ClientScript.RegisterStartupScript(this.GetType(), "", "alert('上传成功');", true);
                        info.Text = "";
                        Image.ImageUrl = "upLoad/" + imgName;
                        info.Text += "路径:" + up.PostedFile.ContentType;
                    }
                    catch
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "", "alert('上传失败');", true);
                    }
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请选择图片');", true);
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "alert('选择要上传的图片');", true);
            }
        }

     ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请选择图片');", true);

    若是gif图像,则ContentType的值为image/gif

  • 相关阅读:
    php中的heredoc和nowdoc对比
    PHP官方网站及PHP手册
    php扩展编译方法
    linux下修改时间和时区
    个人觉得非常好用的mysql客户端工具HeidiSQL
    mysql主从复制总结
    mysql优化的21条经验(转)
    mysql存储引擎选择(转)
    show profiles 分析sql耗时瓶颈
    tar命令的使用方法
  • 原文地址:https://www.cnblogs.com/qiushuixizhao/p/3312017.html
Copyright © 2011-2022 走看看