zoukankan      html  css  js  c++  java
  • 文件上传处理

    .ashx:

     string _delfile = DTRequest.GetString("DelFilePath");
                HttpPostedFile _upfile = context.Request.Files["Filedata"];
                bool _iswater = false; //默认不打水印
                bool _isthumbnail = false; //默认不生成缩略图

                if (DTRequest.GetQueryString("IsWater") == "1")
                    _iswater = true;
                if (DTRequest.GetQueryString("IsThumbnail") == "1")
                    _isthumbnail = true;
                if (_upfile == null)
                {
                    context.Response.Write("{"status": 0, "msg": "请选择要上传文件!"}");
                    return;
                }
                UpLoad upFiles = new UpLoad();
                string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater);
                //删除已存在的旧文件
                if (!string.IsNullOrEmpty(_delfile))
                {
                    Utils.DeleteUpFile(_delfile);
                }
                //返回成功信息
                context.Response.Write(msg);
                context.Response.End();

    public class DTRequest
    {
        public static string GetQueryString(string strname)
        {
            return DTRequest .GetQueryString( strname, false);
        }
        public static string GetQueryString(string strname,bool sqlSafeCheck)
    {
        string resutl;
        if (HttpContext.Current.Request.QueryString[strname] == null)
        {
            resutl = "";
        }
        else
        {
            if (sqlSafeCheck && !IsSafeSqlString(HttpContext.Current.Request.QueryString[strname]))
            {
                resutl = "unsafe string";
            }
            else
            {
                resutl =HttpContext.Current.Request.QueryString[strname ];
            }
        }
        return resutl;
        }
        public static bool IsSafeSqlString(string str)
        {
            return !Regex.IsMatch(str, "[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']");
        
        }
     
    }
    public class Regex : ISerializable
    {
        protected internal RegexOptions roptions;
        private Regex(string pattern,RegexOptions options,bool useCache)
        {
            //......
        }
     

          public static bool IsMatch( string input,string pattern)
        {
            return new Regex(pattern, RegexOptions.None, true).IsMatch(input);
        }
          public bool IsMatch(string input)
          {
              if (input == null)
              {
                  throw new ArgumentNullException("input");
              }
              return null == this.Run(true, -1,input, 0, input.Length, this.UseOptionR() ? input.Length : 0);
          
          }
          protected bool UseOptionR()
          {
              return (this.roptions & RegexOptions.RightToLeft) != RegexOptions.None;
    //          &和&&都可以用作逻辑与的运算符,表示逻辑与(and),当运算符两边的表达式的结果都为true时,整个运算结果才为true,否则,只要有一方为false,则结果为false。
    //&&还具有短路的功能,即如果第一个表达式为false,则不再计算第二个表达式,例如,对于if(str != null && !str.equals(“”))表达式,当str为null时,后面的表达式不会执行,
              //所以不会出现NullPointerException如果将&&改为&,则会抛出NullPointerException异常。If(x==33 & ++y>0) y会增长,If(x==33 && ++y>0)不会增长
    //&还可以用作位运算符,当&操作符两边的表达式不是boolean类型时,&表示按位与操作,我们通常使用0x0f来与一个整数进行&运算,来获取该整数的最低4个bit位,例如,0x31 & 0x0f的结果为0x01。
                    }
          internal Match Run(bool quick, int prevlen, string input, int beginning, int length, int startat)
          {
              if (startat < 0 || startat > input.Length)
              {
                //throw new ArgumentOutOfRangeException("start",SR.GetString("BeginIndexNotNegative");
              }
            
              return ;
          
          }

  • 相关阅读:
    51nod 1138 【数学-等差数列】
    hdoj3665【简单DFS】
    hdoj3664【DP】
    51nod1270 【dp】
    51nod 1069【思维】
    关于一些数学符号和概率的阐述;
    51nod 1428【贪心】
    51nod 1133【贪心】
    51nod1127【尺取】
    51nod1126【矩阵快速幂】
  • 原文地址:https://www.cnblogs.com/zhubenxi/p/5329847.html
Copyright © 2011-2022 走看看