How can PHP be used to restrict file uploads to only allow images with the .jpg extension and a maximum size of 250 x 250 pixels?

To restrict file uploads to only allow images with the .jpg extension and a maximum size of 250 x 250 pixels, you can use PHP to check the file extension and dimensions before allowing the upload to proceed. This can be achieved by checking the file extension using the pathinfo() function and verifying the image dimensions using the getimagesize() function.

if ($_FILES['file']['type'] == 'image/jpeg' && $_FILES['file']['size'] <= 250*250) {
    $image_info = getimagesize($_FILES['file']['tmp_name']);
    if ($image_info[0] <= 250 && $image_info[1] <= 250) {
        move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $_FILES['file']['name']);
        echo 'File uploaded successfully.';
    } else {
        echo 'Image dimensions must be 250 x 250 pixels or less.';
    }
} else {
    echo 'Only JPEG images with a maximum size of 250 x 250 pixels are allowed.';
}