转载地址:
点击打开链接
// <summary>
/// C#检测真实文件类型函数
/// </summary>
/// <param name="hifile"></param>
/// <returns></returns>
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();