asp.net上传文件检测类型(上传过程中,非本地检测)
private bool IsAllowedExtension(HttpPostedFile hifile) { bool ret = false; System.IO.BinaryReader r = new System.IO.BinaryReader(hifile.InputStream); string fileclass = ""; byte buffer; try { buffer = r.ReadByte(); fileclass = buffer.ToString(); buffer = r.ReadByte(); fileclass += buffer.ToString(); } catch { return false; } r.Close(); //fs.Close(); /*文件扩展名说明 *4946/104116 txt *7173 gif *255216 jpg *13780 png *6677 bmp *239187 txt,aspx,asp,sql *208207 xls.doc.ppt *6063 xml *6033 htm,html *4742 js *8075 xlsx,zip,pptx,mmap,zip *8297 rar *01 accdb,mdb *7790 exe,dll *5666 psd *255254 rdp *10056 bt种子 *64101 bat *4059 sgf */ //纯图片 String[] imgeType = { "7173", //gif "255216", //jpg "13780" //png }; //文件 String[] fileType = { "4946", "208207", "8075", "8297" }; //这里只检查了图片 for (int i = 0; i < imgeType.Length; i++) { if (fileclass == imgeType[i]) { ret = true; break; } } //Response.Write(fileclass);//可以在这里输出你不知道的文件类型的扩展名 return ret; }