What are potential pitfalls when uploading images in PHP?

One potential pitfall when uploading images in PHP is not validating the file type properly. This can lead to security vulnerabilities if a malicious user uploads a script disguised as an image. To solve this, make sure to check the file type using functions like `exif_imagetype()` or checking the file extension.

// Check file type before uploading
$allowed_types = array(IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF);
$file_type = exif_imagetype($_FILES['file']['tmp_name']);

if (!in_array($file_type, $allowed_types)) {
    echo "Invalid file type. Only JPEG, PNG, and GIF files are allowed.";
    exit;
}

// Continue with image upload process