What are some common issues with PHP image upload functionality, specifically regarding file type validation?

One common issue with PHP image upload functionality is the lack of proper file type validation, which can lead to security vulnerabilities such as allowing users to upload malicious files. To solve this, you can implement server-side validation to check the file type before allowing the upload to proceed.

// Check if the uploaded file is an image
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif'];
if (!in_array($_FILES['file']['type'], $allowedTypes)) {
    die('Invalid file type. Only JPEG, PNG, and GIF files are allowed.');
}

// Proceed with the file upload process
// Your upload code here