$file = new CUploadedFile('path/to/image.jpg'); if(CFile::IsImage($file->getType())) { echo "The file is an image"; } else { echo "The file is not an image"; }
$fileTypes = ['image/jpeg', 'image/png', 'image/gif']; if(in_array($file->getType(), $fileTypes)) { echo "The file is an image"; } else { echo "The file is not an image"; }In this example, we define an array containing the MIME types of image files. We then use the in_array method to check if the result of $file->getType() is in the array. If it is, we output "The file is an image". Otherwise, we output "The file is not an image". The CFile class is part of the Yii framework, specifically the yii\helpers package.