PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I read previous posts and followed the advice about mime types. Yet when I try to display a blob from a mysql database, php prints binary data on the page instead of rendering the data as in image.
This is a phonebook data base. And the entry is the users profile picture. The data structure for the image is a blob. Here is how I am printing the output:
Are you storing the whole image breakdown as a value in the database and then getting php to render the image for you so you actually never have an image on your server its just code in your database?
// select our database
mysql_select_db("blob") or die(mysql_error());
// get the image from the db
$sql = "SELECT image FROM blob WHERE image_id=0";
// the result of the query
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
// set the header for the image
header("Content-type: image/png");
echo mysql_result($result, 0);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
while($row=mysql_fetch_array($result)) {
echo 'This is '.$row['image_name'].' from the database<br />';
echo '<img '.$row['image_size'].' src="blob.php?image_id='.$_GET['image_id'].'">';