zoukankan      html  css  js  c++  java
  • 上传图片2

    <tr>
                                 <td align="right">推荐小图:</td>
                                 <td align="left" colspan="3">
                                     <asp:FileUpload ID="fulImage" runat="server" Width="407px" /><br />
                                     <asp:Image ID="imgBus" runat="server" Width="140px" Height="100px" ImageUrl="/Images/Demo.gif"/><font color="red">(图片大小:

    300*214px)</font>
                                     &nbsp;&nbsp;&nbsp;&nbsp;
                                     <asp:Button ID="btnUpImg"
                                         runat="server" Text="上传图片" onclick="btnUpImg_Click" Width="100px" Height="30px" />
                                 </td>
                             </tr>

     //推荐大图片
                string bigpic;
                if (imgbigBus.ImageUrl.Equals("~/Images/businessDemo.gif"))
                    bigpic = "";
                else
                    bigpic = imgbigBus.ImageUrl.Trim();
      protected void btnUpImg_Click(object sender, EventArgs e)
        {
            string picName = "";
            string file = "/images/CollegeImages/";

            if (fulImage.FileName != null && fulImage.FileName != "")
            {
                picName = UploadPicture.UploadInfo(fulImage, file);

                if (picName == null)
                    Response.Write("<script>alert('图片上传失败!')</script>");
                else
                    imgBus.ImageUrl = picName;
            }
        }
    public static string UploadInfo(FileUpload fu, string file)
        {
            Random myRd = new Random();

            string prefix = System.IO.Path.GetExtension(fu.FileName).ToLower();
            string fileName = "";
            if (prefix.Equals(".jpg") || prefix.Equals(".gif") || prefix.Equals(".jpeg") || prefix.Equals(".png"))
            {
                string strFileName = DateTime.Now.ToString().Replace("-", "").Replace(":", "").Replace(" ", "") + myRd.Next(1000) + prefix;
                string name = @System.Web.HttpContext.Current.Server.MapPath(file.Replace("~", "") + strFileName);
                //System.Web.HttpContext.Current.Server.MapPath(file + strFileName);
                fileName = file + strFileName;
                name = name.Replace("zhuzhan\images", "images");
                fu.SaveAs(name);
                return fileName;
            }
            else
                return null;
        }

  • 相关阅读:
    CoreAnimation6-基于定时器的动画和性能调优
    CoreAnimation5-图层时间和缓冲
    CoreAnimation4-隐式动画和显式动画
    CoreAnimation3-专用图层
    CoreAnimation2-视觉效果和变换
    CoreAnimation1-图层树、寄宿图以及图层几何学
    Quartz-2D绘图之路径(Paths)详解
    Quartz-2D绘图之图形上下文详解
    Objective-C设计模式——抽象工厂模式Abstract Factory(对象创建)
    Objective-C设计模式——工厂方法模式virtual constructor(对象创建)
  • 原文地址:https://www.cnblogs.com/candyzhmm/p/4281841.html
Copyright © 2011-2022 走看看