function isValidPdf($filePath) {
    // 1. Check if file exists
    if (!file_exists($filePath)) {
        return false;
    }

    // 2. Check MIME type (Requires Fileinfo extension, enabled by default in PHP)
    $finfo = new finfo(FILEINFO_MIME_TYPE);
    $mimeType = $finfo->file($filePath);
    if ($mimeType !== 'application/pdf') {
        return false;
    }

    // 3. Check PDF Magic Number (%PDF-)
    $handle = fopen($filePath, 'rb');
    if (!$handle) {
        return false;
    }
    
    $firstBytes = fread($handle, 5);
    fclose($handle);

    if ($firstBytes !== '%PDF-') {
        return false;
    }

    return true;
}