How to read images from MySQL database using PHP?

后端 未结 2 1548
半阙折子戏
半阙折子戏 2020-12-12 05:19

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

2条回答
  •  轮回少年
    2020-12-12 06:00

    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()
    
    

    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.

提交回复
热议问题