I'm trying to create user avatars. I'm just trying to make sure its secure. What is the best way to check if the file is an actual image, and not anything else.
I've tried this
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
} else {
echo "File is not an image.";
}
Although this seems to work on some images, but other images like photos seem to make it fail. Photos that i've taken with my phone seem to make it appear with "File is not an image" while others make it appear with an image.
I've also been checking the file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
}
$imageFileType=$_FILES["fileToUpload"]["type"].