How,to,show,images,stored,in,a,database,php

Mert 9/1/2016 0

How to show images stored in a database in PHP

PHP
    <?php 

    // show_desc.php 
    require("conn.php"); 

      // you may have to modify login information for your database server 

      $query = "select description, id from binary_data "; 
      $result = connect($query); 

      while ($rows = MYSQL_FETCH_ARRAY($result)) 
      { 
      echo $rows['description']; 
      echo "<br><br>"; 
       
      echo "<img src=\"show_image.php?id=".$rows['id']."\">\n"; 


    }; 
    ?> 



    <?php 
    //show_image.php 

    require("conn.php"); 
    //check to see if the id is passed 
    if(isset($_GET['id'])) { 
      $id=$_GET['id']; 


      $query = "select bin_data, filetype from binary_data where id=$id"; 
      //echo $query; 
      $result = connect($query); 
      $row = mysql_fetch_array($result); 
      { 
       $data = $row['bin_data']; 
       $type = $row['filetype']; 
      } 
      if ($type=="pjpeg") $type = "jpeg"; 
      Header( "Content-type: $type"); 
       
      echo $data; 

    } 
    ?> 

Database table: 

CREATE TABLE binary_data ( 
id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, 
description CHAR(50), 
bin_data LONGBLOB, 
filename CHAR(50), 
filesize CHAR(50), 
filetype CHAR(50) 
);
 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments