What is the best way to implement a size limit for avatar images in a PHP forum?

To implement a size limit for avatar images in a PHP forum, you can use the `$_FILES` superglobal to check the size of the uploaded image before saving it to the server. You can compare the size of the image against a predefined limit and display an error message if it exceeds the limit.

if ($_FILES['avatar']['size'] > 500000) {
    echo "Error: Image size exceeds the limit of 500KB.";
} else {
    // Save the image to the server
}