I'm trying to display an image from a base64 encoded format. I have wrote the following php code for that. But it only shows a blank image of size 20px x 20px. How to correct this snippet?
<?php
$username = "root";
$password = "";
$host = "localhost";
$connector = mysql_connect($host, $username, $password) or die("Unable to connect");
$selected = mysql_select_db("postman", $connector) or die("Unable to connect");
//execute the SQL query and return records
$result = mysql_query("SELECT image FROM mail ");
?>
this is the connectivity code and below is the table created to show images within that table.......
<table border="2" id="tblData" bgcolor="#ACAAFC" align="center">
<thead>
<tr >
<th><h4>IMAGE</h4></th>
</tr>
</thead>
<tbody>
</tbody>
here is the basic running in the looping body where the image is being fetched and displayed but the image is not being shown on the execution of the code, using the function base64_decode. so as to decode the image string array.
<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>"
$row['image'];
$str = implode(';', $row);
$imgstr = "image/jpeg;base64,$str";
$new_data = explode(";", $imgstr);
$type = $new_data[0];
$data = explode(",", $new_data[1]);
header("Content-type:" . $type);
echo "<td>" . base64_decode($data[1]) . "</td>";
echo "</tr>";
"</table>";
}
?>
</tbody>
</table>
</form>
<?php mysql_close($connector); ?>