zoukankan      html  css  js  c++  java
  • 附件,图片等上传代码

    <!--Html-->
    <td colspan="2"><input  type='file' name='txfile' require='true' datatype='require' style="468px;" class="write_3" />
     HttpPostedFile tx = Request.Files["txfile"];
    if (tx.FileName != null && tx.FileName.ToString() != "")
                        {
                            if (tx.ContentLength > 1024 * 50)
                            {
                                base.Alert("上传图标不能超过50KB");
                                return;
                            }
                            oldtx = UpLoad(tx);
    
                        }
    //method
      public string UpLoad(HttpPostedFile hpf)
            {
                string strExt = hpf.FileName.Remove(0, hpf.FileName.LastIndexOf("."));
                string[] Er = { ".jpg", ".png", ".bmp" };
                string lower = strExt.ToLower();
                int len = Er.Length;
                bool btrue = false;
                for (int num = 0; num < len; num++)
                {
                    if (lower == Er[num])
                    {
                        btrue = true;
                    }
                }
                if (!btrue)
                {
                    //"图标格式不正确,请上传图标";
                    return "";
                }
    
                Random ra = new Random();
                DateTime datNow = DateTime.Now;
                string MyFileName = datNow.Year.ToString() + datNow.Month.ToString() + datNow.Day.ToString() + datNow.Hour.ToString() + datNow.Minute.ToString() + datNow.Second.ToString() + datNow.Millisecond.ToString();
                string strNewName = MyFileName + ra.Next(10000) + hpf.FileName.Remove(0, hpf.FileName.LastIndexOf("."));//文件名
                string strpath = Server.MapPath("~/UploadFiles/affix/") + strNewName;
                hpf.SaveAs(strpath);
                return "/UploadFiles/affix/" + strNewName;//相对路径
            }
  • 相关阅读:
    P4995 跳跳!
    P4306 [JSOI2010]连通数
    P1339 [USACO09OCT]热浪Heat Wave
    P2002 消息扩散
    P3388 【模板】割点(割顶)
    P1656 炸铁路
    P2863 [USACO06JAN]牛的舞会The Cow Prom
    P1516 青蛙的约会
    3.从尾到头打印链表
    2.替换空格
  • 原文地址:https://www.cnblogs.com/zwnet/p/2673245.html
Copyright © 2011-2022 走看看