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

  • 相关阅读:
    iphone、UI设计和PKM的混谈
    社保名单核对的难题
    LVDS技术原理和设计简介
    系统级芯片设计语言和验证语言的发展
    芯片封装(Chip Package)类型70种
    数字电平标准 TTL CMOS ECL LVDS CML...
    什么是施密特触发器(Schmitt Trigger)?
    组合逻辑电路中竞争冒险的分析
    ASIC设计流程(ASIC design flow)
    这18条背下来没人敢和你忽悠CPU
  • 原文地址:https://www.cnblogs.com/candyzhmm/p/4281841.html
Copyright © 2020-2023  润新知