how to Display Multiple Images (blob) from mysql using php?

后端 未结 2 699
栀梦
栀梦 2021-01-16 03:16

I\'m trying to display multiple images using PHP and MySql database, even if using the while loop I don\'t get all of the images, I only get one, I mean the fir

2条回答
  •  萌比男神i
    2021-01-16 04:07

    A possible way to solve this problem is to have a separate script to dynamically output the contents of the image eg. :

    image.php

    header('Content-type: image/jpg');
    
    // DataBase query and processing here...
    
    echo $data['myImage'];
    

    and call it whenever you need to show images stored in your DB eg. inside your loop:

    echo '';
    

    But storing images in the database will take a toll on your server and unless they're really small or you have a good reason to do so, you should only store their physical location on the disk.

    You can also use this approach if you wish to hide image location from your users, or control access, but there are better and faster alternatives for that case.

提交回复
热议问题