vs2005中用FileUpload上传图片怎么识别后缀名保存 只能用定好的格式来存上传的文件 不能自动识别他的格式··· 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先定义一个数组保存所想要保存在数据库的文件后缀名,当上传的文件时,提取文件的后缀名看是否在数据里面,如果里面就pass,不在里面就弹出提示。。 //平时可通过文本方式检测扩展名,//如果要检测真实的物理扩展名,可参考以下方法//检测要上传文件的真实文件名,判断是否为允许的类型 public static bool IsAllowedExtension(string FilePath) { System.IO.FileStream fs = new System.IO.FileStream(FilePath, 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" || fileclass == "6677" || fileclass == "13780")//说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar { return true; } else { return false; } } buffer = r.ReadByte();fileclass = buffer.ToString();buffer = r.ReadByte();fileclass += buffer.ToString();这是读后缀名的吗? FreeTextBox问题 sql查询问题,急,跪求答案 CuteEditor使用问题 如何获取网页上提交的数据 无法将类型为“personnelModel.RS_HolidayType”的对象强制转换为类型“System.Data.DataRowView”。 datagrid删除数据时出现异常 刚学啊。。不好意思,问个问题 关于使用网页修改AD用户密码的问题 asp.net读取Excel的 问题? 实现类似Windows资源管理器的DataGrid 上传远程网站出现的问题 2道ASP.Net选择题 帮忙选一下.
//如果要检测真实的物理扩展名,可参考以下方法//检测要上传文件的真实文件名,判断是否为允许的类型
public static bool IsAllowedExtension(string FilePath)
{
System.IO.FileStream fs = new System.IO.FileStream(FilePath, 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" || fileclass == "6677" || fileclass == "13780")//说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
{
return true;
}
else
{
return false;
} }
fileclass = buffer.ToString();
buffer = r.ReadByte();
fileclass += buffer.ToString();这是读后缀名的吗?