0

I have some data stored in a MySQL database. How to display the stored image data(mediumblob) along with other data in a .php page.

4

1 回答 1

0
<?php
$db = new mysqli('host', 'user', 'pass', 'db'); //Connect to the DB
$res = $db->query('SELECT * FROM `table`'); //Query the DB

while($i = $res->fetch_object()) { //Loop through the images in the DB
    echo '<img src="data:image/jpeg;base64,',base64_encode($i->image),'" /><br />'; //Print out each image in the DB  as a base64 encoded string
}
?>

您需要将image/jpeg部件更改为图像的任何格式。此外,最好将图像存储在数据库之外,并将图像的路径存储在数据库中(如 asprin 所说)。

于 2012-07-24T08:17:29.677 回答