C# 检测真实的文件类型函数
2024-09-06 11:26:16
private 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(fs);
string fileclass = "";
byte buffer;
try
{
buffer = r.ReadByte();
fileclass = buffer.ToString();
buffer = r.ReadByte();
fileclass += buffer.ToString();
}
catch
{
return false;
}
r.Close();
fs.Close();
/*文件扩展名说明
*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
*/ String[] fileType = { "", "", "", "", "", "", "", "", "" }; for (int i = ; i < fileType.Length; i++)
{
if (fileclass == fileType[i])
{
ret = true;
break;
}
}
return ret;
}
最新文章
- vs使用
- 第37课 深度解析QMap与QHash
- java jar包收集
- 如何查看经过编码的cookie?
- C# 多线程详解 Part.01(UI 线程、子线程)
- Codeforces Round #382 (Div. 2) A. Ostap and Grasshopper bfs
- Nginx在Windows系统和Linux系统下的重启
- 5方与5W
- 单件模式Singleton来控制窗体被重复或多次打开
- SQL语句优化(转摘)
- poj 3082多边形相交 &#39;Roid Rage
- Boosting 和梯度Boosting
- css 修改默认滚动条样式
- Jenkins 配置 Git 错误解决:CAfile: C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
- java 写一个JSON解析的工具类
- ASP.NET Core Middleware管道介绍
- Kubernetes Ingress 学习
- 一次关于()=>;({})的使用
- 前端开发面试题-CSS(转载)
- Linux Install redis