Aaron Aaron - 11 months ago 51
PHP Question

HOW to call php in img src tag?

This is the piece of my code from index.php:

<div class="row">
$conn = mysql_connect("localhost","root","");
$res = mysql_query("select * from `film` ORDER BY ID DESC");
while($row = mysql_fetch_array($res)){
?><div class='col-xs-2'><?php
?><p style="position:relative;left:-40px"><?php echo $row["Cim"];?></p><?php
?> <img src="php/imageView.php?ID=<?php echo $row["ID"];?>" class="img-responsive" style="width:200px;height:250px;" alt="Image"> <?php

This is the imageView.php:

$conn = mysql_connect("localhost","root","");
mysql_select_db("imdb_db") or die(mysql_error());
if(isset($_GET['ID'])) {
$sql = "SELECT `Boritokep` FROM `film` WHERE ID=". $_GET['ID'];
$result = mysql_query("$sql") or die("<b>Error:</b> Problem on Retrieving Image BLOB<br/>" . mysql_error());
$row = mysql_fetch_array($result);
echo $row["Boritokep"];


And this is the result:

enter image description here

php/imageView.php?ID=<?php echo $row["ID"]
I getting the path of my file:


Why it doesn't displays the image?

Answer Source

Why it doesn't displays the image?

Because php/imageView.php?ID=<?php echo $row["ID"];?> returns the path of an image and doesn't return the image itself.

imageView.php can take that path and redirect the user agent to it:

header(sprintf('Location: %s', $row["Boritokep"]));