C#文件上傳頭文件
//這邊HttpPostedFile 因爲我靜態頁上傳的,你也可以改爲FileUplaod
publicbool isImage(HttpPostedFile postfile)
{
string[] exten = { "255216", "7173", "13780" };
int contentLength = postfile.ContentLength;
byte[] imgArray =newbyte[contentLength];
postfile.InputStream.Read(imgArray, 0, contentLength);
MemoryStream ms =new MemoryStream(imgArray);
BinaryReader br =new BinaryReader(ms);
string filecess ="";
byte buffer;
try
{
buffer = br.ReadByte();
filecess = buffer.ToString();
buffer = br.ReadByte();
filecess += buffer.ToString();
}
catch { }
finally { br.Close(); ms.Dispose(); ms.Close(); }
foreach (string s in exten)
{
if (s == filecess)
returntrue;
}
returnfalse;
}
//這是一些文件頭格式
publicenum FileExtension
{
JPG =255216,
GIF =7173,
PNG =13780,
SWF =6787,
RAR =8297,
ZIP =8075,
_7Z =55122
}
publicbool isImage(HttpPostedFile postfile)
{
string[] exten = { "255216", "7173", "13780" };
int contentLength = postfile.ContentLength;
byte[] imgArray =newbyte[contentLength];
postfile.InputStream.Read(imgArray, 0, contentLength);
MemoryStream ms =new MemoryStream(imgArray);
BinaryReader br =new BinaryReader(ms);
string filecess ="";
byte buffer;
try
{
buffer = br.ReadByte();
filecess = buffer.ToString();
buffer = br.ReadByte();
filecess += buffer.ToString();
}
catch { }
finally { br.Close(); ms.Dispose(); ms.Close(); }
foreach (string s in exten)
{
if (s == filecess)
returntrue;
}
returnfalse;
}
//這是一些文件頭格式
publicenum FileExtension
{
JPG =255216,
GIF =7173,
PNG =13780,
SWF =6787,
RAR =8297,
ZIP =8075,
_7Z =55122
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.