//真正判断文件类型的关键函数
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; } }

  

最新文章

  1. 微信小程序-上传下载
  2. 这是经典的"百马百担"问题,有一百匹马,驮一百担货,大马驮3担,中马驮2担,两只小马驮1担,问有大,中,小马各几匹?
  3. 使用oracle utl_http包需要注意的事项
  4. 10月20日MySQL数据库作业解析
  5. Android FM模块学习之一 FM启动流程
  6. plateform_driver_register和plateform_device_register区别
  7. AngularJs学习(1)
  8. coroutine
  9. POJ 1472 Coins (多重背包+滚动数组)
  10. java反射中Method类invoke方法的使用方法
  11. JSP Cookie的使用
  12. 百度鹰眼Java接口调用增删改查实例
  13. C++通过ADO读写Excel文件
  14. Beta冲刺Day6
  15. typescript简介
  16. Android Studio 插件开发详解三:翻译插件实战
  17. 使用Java方式连接HDFS
  18. 转://Oracle PL/SQL 优化与调整 -- Bulk 说明
  19. C#中转义字符[转]
  20. tomcat添加context方式部署web应用

热门文章

  1. kuangbin专题16I(kmp)
  2. Chrome插件-Postman Interceptor
  3. Python——用socket和线程实现全双工收发数据
  4. t-sql read xlsx
  5. CF352B Jeff and Periods 模拟
  6. kuangbin专题七 POJ3468 A Simple Problem with Integers (线段树或树状数组)
  7. Spring注解实现定时功能以及Quartz定时器
  8. docker容器时间不对及java程序时间不对解决
  9. 2-32 while
  10. hdu-4513吉哥系列故事——完美队形II--最长回文