C#文件上传头文件

来源:互联网 发布:小学生电脑绘画软件 编辑:程序博客网 时间:2024/05/16 15:54
//这边HttpPostedFile 因为我静态页上传的,你也可以改为FileUplaod
publicbool isImage(HttpPostedFile postfile)
        {
            string[] exten = { "255216", "7173", "13780" };
            int contentLength = postfile.ContentLength;
            byte[] imgArray =newbyte[contentLength];
            postfile.InputStream.Read(imgArray, 0, contentLength);
            MemoryStream ms =new MemoryStream(imgArray);
            BinaryReader br =new BinaryReader(ms);
            string filecess ="";
            byte buffer;
            try
            {
                buffer = br.ReadByte();
                filecess = buffer.ToString();
                buffer = br.ReadByte();
                filecess += buffer.ToString();
            }
            catch { }
            finally { br.Close(); ms.Dispose(); ms.Close(); }
            foreach (string s in exten)
            {
                if (s == filecess)
                    returntrue;
            }
            returnfalse;
        }
//这是一些文件头格式
    publicenum FileExtension
    {
        JPG =255216,
        GIF =7173,
        PNG =13780,
        SWF =6787,
        RAR =8297,
        ZIP =8075,
        _7Z =55122
    }
0 0
原创粉丝点击