Jump to content

reading MySQL type BLOB


skaterdav85

Recommended Posts

How do I output an image from a db stored as type blob? I have tried googling it and i can only find scripts that upload images to a db as type blob. The field is called 'cover' and when I did echo $row['cover']; all i get is the binary data.

Link to comment
Share on other sites

You use a separate script with the relevant Internet Media (MIME) type set. E.g., say you have a script image.php:

header("content-type:image/png");$id = (int) $_GET['id'];$result = mysql_query("SELECT cover FROM table WHERE id = $id");$row = mysql_fetch_assoc($result);echo $row['cover'];

Then from another script:

<img src="image.php?id=1" alt="PHP-generated image">

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...