在 PHP 和 MySQL 中将 blob 类型转换为 base64 时显示半图像


half image displayed when converted blob type to base64 in php and mysql

while($row=mysqli_fetch_array($res))
    {
        $image = $row['image'];
        if($counter == 0)
        {
            $Indicators .='<li data-target="#carousel-example-generic" data-slide-to="'.$counter.'" class="active"></li>';
            $slides .= '<div class="item active">
            <div class="fill">
            <img src="data:image/jpg;base64,'.base64_encode($image).'" alt="photo"></div>
          </div>';
        }
        else
        {
            $Indicators .='<li data-target="#carousel-example-generic" data-slide-to="'.$counter.'"></li>';
            $slides .= '<div class="item"><div class="fill">
            <img src="data:image/jpg;base64,'.base64_encode($image).'" alt="photo"></div>
          </div>';
        }
        $counter++;
    }

显示从顶部到图像中间某处的小部分。我将图像存储在mysql数据库中,图像类型是blob。当尝试使用 php 进行转换和显示时,它们似乎从底部切了一半,我认为它们没有完全转换。原始图像:原始图像在base64中转换后,图像显示如下:将图像转换为base64

如果您

只使用BLOB则不足以存储您提供的图像数据,您必须使用MEDIUMBLOBLONGBLOB

最大尺寸

BLOB: ~ 63KB
MEDIUMBLOB: ~ 16MB
LONGBLOB: ~ 4GB

有关BLOB和其他MySql字段长度的更多信息,您可以在此处查看:http://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html