我无法从mysql加载blon。我能够将图像插入表格中。每当我保存blob时,我得到[BLOB - 82.6 KiB]值,我认为这是正确的。但是,当我试图显示它时,我会得到特殊的字符而不是图像。 (����JFIF``���E)
这里仅供参考,我的连接字符串
$db = new PDO( 'mysql:host=localhost;dbname=wedding;charset=utf8', 'root','' );
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
这是我保存图片blob的PHP代码
if($_SERVER['REQUEST_METHOD']=='POST'){
$image = addslashes(file_get_contents($_FILES['photo']['tmp_name']));
}
if(!empty($image)){
try{
require 'scripts/connection.php';
$updateprofile = "UPDATE users SET "
. "photo = :photo "
. "WHERE id = :id";
$q = $db->prepare($updateprofile);
$q->execute(array(
':photo' => $image,
':id' => $loggedid
));
echo "Uploaded successfully";
}catch(PDOException $exception){
echo "Error: " . $exception->getMessage();
}
}else{
echo "Please choose a file";
}
这是我的PHP代码,用于检索并显示它
$stmt = $db->prepare('SELECT photo FROM users WHERE id=:loggedid ');
$stmt ->execute(array(':loggedid'=> $loggedid));
$stmt->bindColumn(1, $image, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);
header("Content-Type: image");
echo $image;
表用户设置为utf8_unicode_ci
请帮助..提前致谢