Image does not appear in html but it works in php -


i need display image database html page; wrote code displays image in php, can't output image on html.

 <?php  class kep {     function proba(){            $id=3;         $db = new pdo("mysql:host=localhost;dbname=nyarigyak;charset=utf8", 'root', '');         $stmt = $db->prepare('select data, mime  kepek  kepek_id = ?');         $stmt->execute(array($id));         $stmt->bindcolumn(1, $data, pdo::param_lob);          $stmt->bindcolumn(2, $mimetype, pdo::param_str);         $ret = $stmt->fetch(pdo::fetch_bound);           header('content-type: ' . $mimetype);         header('content-length: ' . strlen($data));         return $data;         }     } ?>  <?php $g = new kep(); echo $g->proba();  ?> 

this code works , displays image. if put html tag not work. how can make work?

<?php class kep { function proba(){        $id=3;     $db = new pdo("mysql:host=localhost;dbname=nyarigyak;charset=utf8", 'root', '');     $stmt = $db->prepare('select data, mime  kepek  kepek_id = ?');     $stmt->execute(array($id));     $stmt->bindcolumn(1, $data, pdo::param_lob);      $stmt->bindcolumn(2, $mimetype, pdo::param_str);     $ret = $stmt->fetch(pdo::fetch_bound);       header('content-type: ' . $mimetype);     header('content-length: ' . strlen($data));     return $data;     } } ?> <html> <?php $g = new kep(); echo $g->proba();  ?> </html> 

you can't place image in middle of html code. there 2 ways show image:

put database retrieval code in separate php file (e.g. image.php) , link it:

<img src="image.php?id=xyz"> 

if insist on embedding image directly can using base64 encoding, explained in this question , answers.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -