我正在尝试以 pdf 格式显示 MySQL 表中的图像。我在执行代码时收到以下错误:
已建立连接 已选择数据库 查询:SELECT * FROM users WHERE id = 31 executed FPDF error: Unsupported image type:/Û7úw‹é(n¼Þcé^Ô£-ûÑŒöÍä¿j÷÷§íÛÉ~•*v¶ g¿½xßnÞkô¯g¥ ¸ßnÞkô©r¶§Ù´®{±Þݼ—és÷¿ÿ¨o%úwµ(ê—Òº<ýïÇêÉ~•çïn;Û·'ý*t Ûa¤túuŒöíä¿j©ô›í›È}+ Ê”´†¶x}"Åûä>•_Çñ>Õ¼‡Ò¥jÔƒª]ž½‰ö§È}+ÏÇ1Ôû¾•*q£j}m¼g´>ï¥oÇ1Ðû¾•*v§ÙáÛ8h}ßj¯â÷ý ¡÷}*t¬mo²§j^ýgÝyÞÆ\aÄŠò¥c[0©r¥`ÿÙ
我已将图像作为 blob 文件存储在我的 mysql 数据库中。我的代码如下:
<?php
require 'fpdf/fpdf.php';
$host = "localhost";
$user = "root";
$pass = "";
$db = "cliniops";
$usertable = "users";
// Create fpdf object
$pdf = new FPDF('P', 'pt', 'Letter');
// Add a new page to the document
$pdf->addPage();
// Try to connect to DB
$r = mysql_connect($host, $user, $pass);
if (!$r) {
echo "Could not connect to server\n";
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "Connection established\n";
}
// Try to select the database
$r2 = mysql_select_db($db);
if (!$r2) {
echo "Cannot select database\n";
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "Database selected\n";
}
// Try to execute the query
$query = "SELECT * FROM users WHERE id = 31";
$rs = mysql_query($query);
if (!$rs) {
echo "Could not execute query: $query";
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "Query: $query executed\n";
}
while ($row = mysql_fetch_assoc($rs)) {
// Get the image from each row
$url = $row['image'];
// Place the image in the pdf document
$pdf->Image($url);
}
// Close the db connection
mysql_close();
// Close the document and save to the filesystem with the name images.pdf
$pdf->Output('images1.pdf', 'F');
?>