What are common pitfalls when handling file uploads in PHP, especially with regards to file types?

Common pitfalls when handling file uploads in PHP, especially with regards to file types, include not validating the file type before processing it, which can lead to security vulnerabilities such as allowing malicious files to be uploaded and executed on the server. To solve this issue, always validate the file type using the `$_FILES['file']['type']` variable before moving the file to its destination.

// Validate file type before moving the file
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif'];
if (!in_array($_FILES['file']['type'], $allowedTypes)) {
    die('Invalid file type. Only JPG, PNG, and GIF files are allowed.');
}

// Move the file to its destination
move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $_FILES['file']['name']);