c#真正判断文件类型
2024-08-28 17:29:06
//真正判断文件类型的关键函数
public static bool IsAllowedExtension2(FileUpload hifile)
{
if (hifile != null)
{
System.IO.FileStream fs = new System.IO.FileStream(hifile.PostedFile.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
string fileclass = "";
byte buffer;
try
{
buffer = r.ReadByte();
fileclass = buffer.ToString();
buffer = r.ReadByte();
fileclass += buffer.ToString(); }
catch
{ }
r.Close();
fs.Close();
if (fileclass == "255216" || fileclass == "7173")//说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
{
return true;
}
else
{
return false;
}
}
else { return false; } }
最新文章
- 微信小程序-上传下载
- 这是经典的";百马百担";问题,有一百匹马,驮一百担货,大马驮3担,中马驮2担,两只小马驮1担,问有大,中,小马各几匹?
- 使用oracle utl_http包需要注意的事项
- 10月20日MySQL数据库作业解析
- Android FM模块学习之一 FM启动流程
- plateform_driver_register和plateform_device_register区别
- AngularJs学习(1)
- coroutine
- POJ 1472 Coins (多重背包+滚动数组)
- java反射中Method类invoke方法的使用方法
- JSP Cookie的使用
- 百度鹰眼Java接口调用增删改查实例
- C++通过ADO读写Excel文件
- Beta冲刺Day6
- typescript简介
- Android Studio 插件开发详解三:翻译插件实战
- 使用Java方式连接HDFS
- 转://Oracle PL/SQL 优化与调整 -- Bulk 说明
- C#中转义字符[转]
- tomcat添加context方式部署web应用