public static bool GetValidUImage(FileUpload fuImage)
{
bool result = false;
try
{
Dictionary imageHeader = new Dictonary();
imageHeader.Add("JPG", new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 });
imageHeader.Add("JPEG", new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 });
imageHeader.Add("PNG", new byte[] { 0x89, 0x50, 0x4E, 0x47 });
imageHeader.Add("TIF", new byte[] { 0x49, 0x49, 0x2A, 0x00 });
imageHeader.Add("TIFF", new byte[] { 0x49, 0x49, 0x2A, 0x00 });
imageHeader.Add("GIF", new byte[] { 0x47, 0x49, 0x46, 0x38 });
imageHeader.Add("BMP", new byte[] { 0x42, 0x4D });
imageHeader.Add("ICO", new byte[] { 0x00, 0x00, 0x01, 0x00 });
byte[] header;
if (fuImage.HasFile)
{
string fileExt;
fileExt = fuImage.FileName.Substring(fuImage.FileName.LastIndexOf('.') + 1).ToUpper();
byte[] tmp = imageHeader[fileExt];
header = new byte[tmp.Length];
fuImage.FileContent.Read(header, 0, header.Length);
if (CompareArray(tmp, header))
{
result = true;
}
else
{
result = false;
}
}
}
catch (Exception ex)
{
}
return result;
}
{
bool result = false;
try
{
Dictionary
imageHeader.Add("JPG", new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 });
imageHeader.Add("JPEG", new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 });
imageHeader.Add("PNG", new byte[] { 0x89, 0x50, 0x4E, 0x47 });
imageHeader.Add("TIF", new byte[] { 0x49, 0x49, 0x2A, 0x00 });
imageHeader.Add("TIFF", new byte[] { 0x49, 0x49, 0x2A, 0x00 });
imageHeader.Add("GIF", new byte[] { 0x47, 0x49, 0x46, 0x38 });
imageHeader.Add("BMP", new byte[] { 0x42, 0x4D });
imageHeader.Add("ICO", new byte[] { 0x00, 0x00, 0x01, 0x00 });
byte[] header;
if (fuImage.HasFile)
{
string fileExt;
fileExt = fuImage.FileName.Substring(fuImage.FileName.LastIndexOf('.') + 1).ToUpper();
byte[] tmp = imageHeader[fileExt];
header = new byte[tmp.Length];
fuImage.FileContent.Read(header, 0, header.Length);
if (CompareArray(tmp, header))
{
result = true;
}
else
{
result = false;
}
}
}
catch (Exception ex)
{
}
return result;
}
Comments