我試圖以PDF格式顯示來自MySQL表格的圖像。當我執行代碼時,我收到以下錯誤:從數據庫上傳pdf上的圖像時使用PHP和mySQL
Connection established Database selected Query: 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');
?>
感謝,但它說發tal error:調用未定義的方法FPDF :: MemImage() – DominicSeb
@DominicSeb哦,忘了包括所需的功能,去提供的網址,它包含整個代碼。 :) –
嘿,謝謝..但我下載了整個代碼,我做了如下..包括所需的功能,但仍然是相同的錯誤 – DominicSeb