我有一个数据库,其中包含用户个人资料和个人资料图片列。现在,列类型为TEXT,但是我想将其更改为BLOB。但是,更改列会导致图像无法正确输出并损坏。我该如何解决这个问题?
我尝试使用Phpmyadmin将列转换为BLOB,但这会导致问题。代码保持不变。当我将BLOB转换回文本时,可以解决此问题,但是我希望该列为BLOB以便于维护。
Php 7.3.5 Mysql 8.0.16
输出图像的代码:
<?php
/* Error handler. Code not shown. Works fine */
/* Checks the login state. Code not shown. Works fine */
$default_pic = base64_decode('Default pic');
header('Content-Type: image/png');
if ($login_state == false) {
/* Echo a not logged in picture if the user is not logged in */
echo $default_pic;
} else {
/* gets the profile picture from the database */
$client_un = $_SESSION['client_un'];
$mysqli = new mysqli("xxx", "xxx", "xxx", "userdata");
$stmt = $mysqli->prepare("SELECT profilepic FROM userdata WHERE username=?");
$stmt->bind_param('s', $client_un);
$stmt->execute();
$stmt->bind_result($profile_pic);
$stmt->fetch();
$stmt->close();
if ($profile_pic == '') {
/* echo a blank picture if the user has not set a picture before */
echo $default_pic;
} else {
/* Echo the profile picture. This part has problems */
echo $profile_pic;
}
}
?>
我期望text和BLOB列类型的两个版本都将输出相同的内容,但是当列为BLOB时,输出为损坏的图片。