• 上传图片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;
        }

  • 相关阅读:
    二进制数组
    model模块
    Decorator [ˈdekəreɪtə(r)] 修饰器/装饰器 -- 装饰模式
    箭头函数
    async [ə'zɪŋk] 函数
    cocos2d-x 事件分发机制 ——触摸事件监听
    算法:高速排序
    [zlib]_[0基础]_[使用Zlib完整解压zip内容]
    设计模式之状态模式(State)摘录
    编写Web Serviceclient訪问www.webxml.com.cn提供的服务
  • 原文地址:https://www.cnblogs.com/candyzhmm/p/4281841.html
Copyright © 2020-2023  润新知