How to view images stored in BLOB format using PHP and MYSQL -


i doing registration form saving image database, image being stored in longblob format. able add , view data accept image part.

here product_register.php code:

<form role="form" method="post" action="product_register.php">     <fieldset>     <div class="form-group">         <input class="form-control" placeholder="product name" name="product_name" type="text" autofocus>       </div>       <div class="form-group">         <input class="form-control" placeholder="product code" name="product_code" type="text" autofocus>       </div>     <div class="form-group">         <input class="form-control" placeholder="product image" name="product_image" type="file" value="">       </div>      <div class="form-group">         <input class="form-control" placeholder="purchase date" name="date" type="date" autofocus>       </div>      <div class="form-group">         <input class="form-control" placeholder="time guarantee" name="time_guarantee" type="text" autofocus>       </div>        <input class="btn btn-lg btn-success btn-block" type="submit" value="submit" name="submit" >   </fieldset>   </form>   <?php      include("db_conection.php");//make connection here      //mysql_close();     if(isset($_post['submit']))       {       $usern = $_session['sess_username'];       $product_name = $_post['product_name'];       $product_code = $_post['product_code'];       $product_image = $_pos['product_image'];       $date = $_post['date'];       $time_guarantee = $_post['time_guarantee'];       $insert_user = "insert product (product_name,product_code,product_image,date,time_guarantee,usern) value ('$product_name','$product_code','$product_image','$date','$time_guarantee','$usern')";         if(mysqli_query($dbcon,$insert_user))          // $result = mysql_query($insert_user);          {             echo "<script type='text/javascript'>alert('product added !!!')</script>";           // echo"<script>window.open('product_register.php','_self')</script>";             //  mysql_close();        }      }   ?> 

here code view view_product.php code:

 <table class="table table-bordered table-hover table-striped" style="table-layout: fixed">     <thead>            <tr>   <!--   <th>user id</th>  -->          <th>product name</th>          <th>product code</th>          <th>product image</th>          <th>date of purchase</th>          <th>time guarantee</th>     <!-- <th>delete user</th> -->        </tr>      </thead>       <?php         mysql_connect("localhost","root","") or die(mysql_error());         mysql_select_db("gmgmt") or die(mysql_error());          //  $view_users_query="select * users role='user'";     //select query viewing users.         //  $view_users_query="select * users role='admin'";     //select query viewing users.         $view_users_query="select * 'product' 'usern' = 'demo'";     //select query viewing users.         //  $run=mysql_query($view_users_query);//here run sql query.    // '".$_session['userid']."'         $check = mysql_query("select * product usern = '".$_session['sess_username']."' ") or die(mysql_error());          while($row=mysql_fetch_array($check))  //while fetch result , store in array $row.         {            $id=$row[0];            $product_name=$row[1];            $product_code=$row[2];            $product_image=$row[3];            $date=$row[4];            $time_guarantee=$row[5];         // $usern=$row[6];         ?>         <tr> <!--here showing results in table -->   <!--     <td><?php echo $id;  ?></td>  -->            <td><?php echo $product_name;  ?></td>            <td><?php echo $product_code;  ?></td>            <td><?php echo "<img src='php/imgview.php?imgid=".$product_image."' />";  ?></td>            <td><?php echo $date;  ?></td>            <td><?php echo $time_guarantee;  ?></td>     <!--   <td><a href="delete.php?del=<?php echo $id ?>"><button class="btn btn-danger">delete</button></a></td> -->           </tr>         <?php } ?>     </table> 

i searched lot didn't find code or method suits needs.

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

use above code display image store in mysql database. hope you


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -