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.";
            }

        }
  • 相关阅读:
    关于读者来信的一些思考
    serializeArray()与serialize()的区别
    懒人代码-顶部栏
    $.ajax()方法详解
    JavaScript(js)对象常用操作,JS操作JSON总结
    js 获取手机浏览器类型,修改css文件的class的值
    阻止在极短的时间重复执行某个函数
    android WebViewClient和WebChromeClient
    java枚举使用详解
    android-async-http
  • 原文地址:https://www.cnblogs.com/ddr888/p/601174.html
Copyright © 2011-2022 走看看