How can one ensure the integrity of uploaded PDF/DOC files in PHP without relying on image processing functions like imagecreatefrompdf?

When uploading PDF/DOC files in PHP, one way to ensure their integrity is by checking their file signatures or MIME types. This can help verify that the uploaded file is indeed a PDF/DOC file and not a malicious script disguised as one. By validating the file type before processing it further, you can prevent potential security risks associated with executing unknown files.

// Validate uploaded file type
$allowedFileTypes = ['application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'];
$uploadedFileType = $_FILES['file']['type'];

if (!in_array($uploadedFileType, $allowedFileTypes)) {
    die('Invalid file type. Only PDF and DOC files are allowed.');
}

// Continue processing the uploaded file
// Your code here...