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);
                        }
                    }
                }

  • 相关阅读:
    计算fibonacci数(多种方法)
    数组求和(两种方法)
    C语言二级指针(指向指针的指针)
    唯品会海量实时OLAP分析技术升级之路
    hive 调优(一)coding调优
    supsplk 服务器被植入木马 挖矿 cpu使用 700%
    OPTS参数设置
    Yarn 内存分配管理机制及相关参数配置
    hive on tez 任务失败
    hive 调优(三)tez优化
  • 原文地址:https://www.cnblogs.com/xqf222/p/3306840.html
Copyright © 2011-2022 走看看