php mysql 图像,如何使用PHP从MySQL数据库中读取图像?

How to read images from MySQL database using PHP?

If the images are stored in a BLOB in the database, how to use the binary data that I get and turn it into an image using src in

or using the CSS property background-image?

Thanks.

解决方案

To directly use the binary data as a an image source, you can use the data URI scheme, for example:

$uri = 'data:image/png;base64,'.base64_encode($row['binary-data']);

This URI can then be used directly as the image’s source:

background-image: url(<?php echo $uri; ?>)

<?php%20echo%20%24uri;%20?>

But that has some substantial disadvantages: Besides the lack of support for these data URIs in older browsers, data URIs do also have disadvantaged regarding payload, caching, and references.