What best practices should be followed when handling file uploads in PHP, especially in relation to image dimensions and file types?

When handling file uploads in PHP, it is important to validate the file type and size to prevent malicious uploads. Additionally, checking the image dimensions can help ensure that only valid images are accepted. This can be done by using functions like `getimagesize()` to get the dimensions of the uploaded image.

// Validate file type
$allowed_types = array('image/jpeg', 'image/png');
if (!in_array($_FILES['file']['type'], $allowed_types)) {
    die('Invalid file type. Only JPEG and PNG files are allowed.');
}

// Validate file size
$max_size = 5 * 1024 * 1024; // 5MB
if ($_FILES['file']['size'] > $max_size) {
    die('File is too large. Maximum file size is 5MB.');
}

// Validate image dimensions
$image_info = getimagesize($_FILES['file']['tmp_name']);
$image_width = $image_info[0];
$image_height = $image_info[1];

if ($image_width < 100 || $image_height < 100) {
    die('Image dimensions are too small. Minimum dimensions required: 100x100 pixels.');
}

// Continue with file upload process