I've a web page that that can be used to upload files. Now I need to check if the image file type is of correct type like png,jpg,jpeg,gif
I am using the mimeType that comes with the request ,but if i am loading the .txt file that was renamed to .jpg file then also mime-type it is showing image/jpg,basically i dont want to upload this files.Now I want to be sure that nobody is able to upload a .txt file that was renamed in .jpg/.png....
For reference i am putting piece of code here:
//storing images into bytearray.
byte[] bFile = baos.toByteArray();
if((bFile [i] & 0xFF) == 0xFF && (bFile[i+1] & 0xFF) == 0xD8 && (bFile[bFile.length - 2] & 0xFF) == 0xFF && (bFile[bFile.length - 1] & 0xFF) == 0xD9)
{
System.out.println("is Image");
}
The above line will only check for jpeg type but i want to check for other image header for file extensions Can someone please point out what exactly needs to be done to check for other image types?
Thanks