I am trying to display an image from a MySQL table in pdf format. I when I execute the code, I receive the following error:
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¥`ÿÙ
I have stored the image in my mysql database as a blob file. My code is as follows:
<?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');
?>