PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$pattern = "\.jpg$";
if(eregi($pattern, {$_FILESї'imagefile']})) {
print("Okay, it's a .jpg.");
// do whatever
} else {
//check for .gif and others and then:
print("Wrong kind of file");
}
I think it would be something like that. The above code probably wouldn't work. It's just an example.
# assuming you've already taken some other
# preventive measures such as checking file
# extensions...
$result_array = getimagesize($file);
if ($result_array !== false) { $mime_type = $result_array['mime'];
switch($mime_type) {
case "image/jpeg":
echo "file is jpeg type";
break;
case "image/gif":
echo "file is gif type";
break;
default:
echo "file is an image, but not of gif or jpeg type";
}
} else {
echo "file is not a valid image file";
} ?>
This example came from PHP.net and addresses the points that have been mentioned.