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

转载地址: 点击打开链接
//
         /// C#检测真实文件类型函数
         ///
         ///
         ///
         public static bool IsAllowedExtension(HttpPostedFile hifile)
         {
             bool ret =  false ;
 
             //System.IO.FileStream fs = new System.IO.FileStream(hifile.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
             System.IO.BinaryReader r =  new System.IO.BinaryReader(hifile.InputStream);
             //hifile.InputStream
             string fileclass =  "" ;
             byte buffer;
             try
             {
                 buffer = r.ReadByte();
                 fileclass = buffer.ToString();
                 buffer = r.ReadByte();
                 fileclass += buffer.ToString();
             }
             catch
             {
                 return false ;
             }
             r.Close();

你可能感兴趣的:(Code,C#)