zoukankan      html  css  js  c++  java
  • 上传图片代码。

    前台是一个upload控件加一个按钮:
    addline.aspx:
    <tr>
        
    <td style=" 30px">&nbsp;<asp:Label ID="Label9" runat="server" Text="Picture URL:"></asp:Label></td>
        
    <td>&nbsp;<asp:TextBox ID="imgurl"
            runat
    ="server">../img/Noimg.jpg</asp:TextBox>
        
    <asp:Label ID="addimg" runat="server" ForeColor="Red"></asp:Label><br />
        
    <asp:Label ID="Label10" runat="server" Text="Choose PIC:"></asp:Label>
        
    <asp:FileUpload ID="imgurl1" runat="server" />
            
    <asp:Button
            
    ID="Button1" runat="server" OnClick="Button1_Click" Text="upload" /></td>
    </tr>

    addline.cs:
    protected void Button1_Click(object sender, EventArgs e)
        
    {
            Boolean fileOK 
    = false;
            String path 
    = Server.MapPath("~/img/tour/");
            String url 
    = "../img/tour/" + imgurl1.FileName;
            
    if (imgurl1.HasFile)
            
    {
                String fileExtension 
    =
                    System.IO.Path.GetExtension(imgurl1.FileName).ToLower();
                String[] allowedExtensions 
    = 
                    
    ".gif"".png"".jpeg"".jpg" };
                
    for (int i = 0; i < allowedExtensions.Length; i++)
                
    {
                    
    if (fileExtension == allowedExtensions[i])
                    
    {
                        fileOK 
    = true;
                    }

                }

            }


            
    if (fileOK)
            
    {
                
                    imgurl1.PostedFile.SaveAs(path
                        
    + imgurl1.FileName);
                    addimg.Text 
    = "File uploaded!";
                    imgurl.Text 
    = url;
               
            }

            
    else
            
    {
                addimg.Text 
    = "Cannot accept files of this type.";
            }

        }
  • 相关阅读:
    同一个ip、不同端口的两个应用,cookie竟然是可以互相访问到
    JS类型判断typeof、instanceof、Object.prototype.toString.call()
    js 控制一次加载一张图片,加载完成后再加载下一张
    cookie机制和session机制的区别
    Do not access Object.prototype method 'hasOwnProperty' from target object
    Vue 中使用mockjs模拟后端数据
    vue遍历数据字典
    this的用法
    关于html5的离线缓存(转帖)
    js正则 (二)
  • 原文地址:https://www.cnblogs.com/ddr888/p/601174.html
Copyright © 2011-2022 走看看