Simple PHP image upload with error handling
Rather than generate the full array of elements that pathinfo() generously offers only to access one value, use the PATHINFO_EXTENSION flag/option (the second parameter) to only ask for what you need.
For best efficiency, don't perform any  unnecessary processes for disquaified incoming data.
If you are going to declare errors at the start as an empty array, you won't need to call empty() which checks if the variable does not exist or if it is empty/falsey/null/zeroish.  You can more simply use !$errors.  Alternatively, don't declare the empty errors array and then use empty to perform the double check.
I assume that there is no point to generating a filename for an invalid submission, so I don't think that I'll support passing it with errors.
I try to avoid declaring single-use and temporary variable where possible.  In this case, I'd avoid temporary variable by always dealing with the array to be returned at the end.


How my recommendations boil down...

function upload_image($path, $file) {
    if ($file["size"] &gt; 2000000) {
        $outcome['errors'][] = "The image cannot be greater than 2MB";
    }

    $ext = strtolower(pathinfo($file["name"], PATHINFO_EXTENSION)); // force lowercase for uniformity

    if (!in_array($ext, ["jpg", "jpeg", "png"])) {
        $outcome['errors'][] = "The image can only be in .jpg, .jpeg or .png format.";
    }

    if (empty($outcome['errors'])) {
         // for the record, randomness does not guarantee uniqueness
        $outcome['name'] = uniqid() . '.' . $ext;
        move_uploaded_file($file["tmp_name"], $path . $outcome['name']);
    }

    return $outcome;
}


If you like rabbit holes, here's a good read regarding the security aspects of your task: https://stackoverflow.com/q/6484307/2943403