Display image from sql

前端 未结 5 572
星月不相逢
星月不相逢 2021-01-22 13:52

I\'ve create a table where I\'ve saved images through \"BLOB\". I need to show those images along with other items. But I don\'t know how to show those images together in the sa

5条回答
  •  孤街浪徒
    2021-01-22 14:40

    The debate of storing blobs versus storing a path to the image file on disk has been debated over and over again. Microsoft provides a research paper comparing the pros and cons of each here. With that said, to display a blob as an image you need to make a call to a separate page and output header information that tells the browser what type of image is stored.

    For example:

    connectToDatabase();
    
    $sql = "SELECT image_blob FROM eportal;";
    
    $result = mysql_query($sql) or die(mysql_error());  
    $row = mysql_fetch_array($result);
    
    header("Content-type: image/jpeg");
    echo $row['image_blob'];
    $db->close();
    

提交回复
热议问题