Check if file is pdf

finfo_file() function

<?php
$file_path = 'example.pdf';

$file_info = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($file_info, $file_path);
finfo_close($file_info);

if ($mime_type === 'application/pdf') {
    echo "The file is a PDF.";
} else {
    echo "The file is not a PDF.";
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *