PHP show image as BLOB mysqli

后端 未结 3 1226
独厮守ぢ
独厮守ぢ 2021-01-20 01:56

I read all possible questions on StackOverflow, I asked all people who I know and no one can help me. I have table in database:

CREATE TABLE IF NOT EXISTS `z         


        
相关标签:
3条回答
  • 2021-01-20 02:22

    Using phpMyAdmin, I had to change the MIME display type to .jpeg on my MySQL image column = avatar_image. Once I made this simple change, it displays in the browser...i.e. the browser was getting the .jpeg data as a BLOB in raw form and did not know what to do with it...but it was a MySQL configuration = MIME type change on the MySQL column that fixed it.

    0 讨论(0)
  • 2021-01-20 02:32

    Try below

    echo '<img src="data:image/png;base64,'.base64_encode( $row['zdjecie'] ).'"/>';
    

    For better maintenance you can add data:image/png;base64 as your header then only echo base64_encode( $row['zdjecie'] ) this will work for single_image.php?id=$id

    0 讨论(0)
  • 2021-01-20 02:36
    1. Don't store images in DB, it's performance suicide.
    2. Don't make your code vulnerable to SQLinjection.
    3. If you must store files in db, store content type. Maybe it's not a png? Or maybe you have a warning/notice printed out? It will break your image.
    0 讨论(0)
提交回复
热议问题