我正在尝试将我插入到网页上显示的 BLOB 数据类型进行转换。
我尝试使用 base64 编码,但它不起作用。
<td> <img src='data:image/jpg;base64,".base64_encode($photo->image)."'/></td> ;
将数据添加到数据库中
echo $imagename=$_FILES["myimage"]["name"];
//Get the content of the image and then add slashes to it
$imagetmp=addslashes (file_get_contents($_FILES['myimage']['tmp_name']));
$photo_image->auditID = $auditID;
$photo_image->critID = $critID;
$photo_image->image = $img;
$photo_image->image_name = $imagename;
$dao->add($photo_image);
从数据库中检索
public function retrieveName($photo_image) {
$sql = 'select * from audit_trans_photo where auditID=:auditID and critID=:critID';
$result = array();
$connMgr = new ConnectionManager();
$conn = $connMgr->getConnection();
$stmt = $conn->prepare($sql);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->bindParam(':auditID', $photo_image->auditID, PDO::PARAM_INT);
$stmt->bindParam(':critID', $photo_image->critID, PDO::PARAM_INT);
$stmt->execute();
if($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$result = new Audit_Trans_Photo($row['auditID'], $row['critID'], $row['image'], $row['image_name']);
}
return $result;
}
edit-view.php
$dao3 = new Audit_Trans_PhotoDAO();
$photo_image = new Audit_Trans_Photo();
$photo_image->auditID = $auditID;
$photo_image->critID = $n_transaction->critID;
$photo = $dao3->retrieveName($photo_image);
$image_p = $photo->image;
echo <td> <img src='data:image/jpg;base64,".base64_encode($photo->image)."'/></td> ;
它只显示一张损坏的图片。
$photo->image
字符串吗?我想检查它是否是有效的 base64 编码。 - hs-dev2 MR