C#检测上传文件类型(真实检测,不通过后缀名)

来源:互联网 发布:mac连接电视没反应 编辑:程序博客网 时间:2024/04/28 03:15
转载地址:点击打开链接
// <summary>
        /// C#检测真实文件类型函数
        /// </summary>
        /// <param name="hifile"></param>
        /// <returns></returns>
        publicstatic bool IsAllowedExtension(HttpPostedFile hifile)
        {
            boolret = false;
 
            //System.IO.FileStream fs = new System.IO.FileStream(hifile.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader r = newSystem.IO.BinaryReader(hifile.InputStream);
            //hifile.InputStream
            stringfileclass = "";
            bytebuffer;
            try
            {
                buffer = r.ReadByte();
                fileclass = buffer.ToString();
                buffer = r.ReadByte();
                fileclass += buffer.ToString();
            }
            catch
            {
                returnfalse;
            }
            r.Close();

0 0
原创粉丝点击