$filename = 'example.png'; $filetype = FileType::getType($filename); echo $filetype; // output: image/png
$allowed_types = ['image/png', 'image/jpeg', 'application/pdf']; if (in_array($_FILES['file']['type'], $allowed_types)) { // file type is valid, process the file } else { // file type is not valid, display an error message }Package Library: The PHP File Type library is not a standalone library, but rather a part of the PHP FileInfo extension which is bundled with most PHP installations. The extension can be enabled in php.ini file or added via package manager.