zoukankan      html  css  js  c++  java
  • C#检测上传图片是否安全函数

    //添加引用System.Text;

    //添加引用System.IO;

    /// <summary>
                /// C#检测上传图片是否安全函数
                /// </summary>
                /// <param name="strPictureFilePath"></param>
                public void CheckPictureSafe(string strPictureFilePath)
                {
                    bool strReturn = true;
                    if (!File.Exists(strPictureFilePath))
                    {
                        StringBuilder str_Temp = new StringBuilder();
                        try
                        {
                            using (StreamReader sr = new StreamReader(strPictureFilePath))    //按文本文件方式读取图片内容
                            {
                                String line;
                                while ((line = sr.ReadLine()) != null)
                                {
                                    str_Temp.Append(line + ",");
                                }
                                //检测是否包含危险字符串
                                if (str_Temp == null)
                                {
                                    strReturn = false;
                                }
                                else
                                {
                                    str_Temp = str_Temp.Replace("'", "''");
                                    string DangerString = "script|iframe|.getfolder|.createfolder|.deletefolder|.createdirectory|.deletedirectory|.saveas|wscript.shell|script.encode|server.|.createobject|execute|activexobject|language=|include|filesystemobject|shell.application";
                                    string[] sArray = DangerString.Split('|');
                                    foreach (string i in sArray)
                                    {
                                        strReturn = true;
                                        break;
                                    }
                                }
                                sr.Close();
                            }
                            if (strReturn)
                            {
                                File.Delete(strPictureFilePath);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(ex.Message);
                        }
                    }
                }

  • 相关阅读:
    springmvc中request的线程安全问题
    SpringMVC数据验证
    Spring验证的错误返回------BindingResult
    chrome扩展
    北京联想招聘-Android高级工程师(5-7年) 加入qq 群:220486180 或者直接在此 留言咨询
    北京联想招聘-Android Framework高级工程师(7-10年) 加入qq 群:220486180 或者直接在此 留言咨询
    北京联想招聘-java 云服务开发工程师 加入qq 群:220486180 或者直接在此 留言咨询
    北京联想招聘-IOS高级 加入qq 群:220486180 或者直接在此 留言咨询
    css 兼容
    appium 几点总结(转)
  • 原文地址:https://www.cnblogs.com/xqf222/p/3306840.html
Copyright © 2011-2022 走看看