PHP - 设法从数据库获取图像URL,但无法获取图像内容和编码

Here's the part of the code that gets the URL, get the file from the URL and encode it into the base64 string.

require_once 'getimage.php';
$getImage = new GetImage();
$imageUrl = $getImage->getImageUrlByUid($senderUid);

if(!empty($imageUrl)) {
    $file = file_get_contents($imageUrl);
    $encodedImage = base64_encode(file_get_contents($file));
    $payload['encoded_image'] = $encodedImage;
} else {
    $payload['encoded_image'] = '';
}

I managed to get the image URL, i.e. $imageUrl, but somehow I keep failing to get the file and get encoded image out of it.

I kept looking for help on the Internet, and every solution looked the same. I still have no idea why I keep failing, and it's been taking ages.

ADDED

I created another file and created this function under a class.

public function getBase64ProfileByUid($uid) {
    $result = $this->conn->query("SELECT profile_image FROM users WHERE unique_id = '$uid'");
    $row = mysqli_fetch_assoc($result);

    $imageUrl = $row['profile_image'];
    if($imageUrl != NULL) {
        $file = file_get_contents($imageUrl);
        $encodedImage = base64_encode($file);
    } else {
        $encodedImage = '';
    }
    return $encodedImage;
}

This doesn't seem to work, either.