Aaron
Aaron

Reputation: 45

How to call php in img src tag?

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

<div class="row">
<?php 
    $conn = mysql_connect("localhost","root","");
    mysql_select_db("imdb_db");
    $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 
        ?></div><?php
    }
    mysql_close($conn);
?>
</div>

This is the imageView.php:

<?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"];
    }

    mysql_close($conn);
?>

And this is the result:

enter image description here

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

uploads/film/pic/5.jpg

Why it doesn't displays the image?

Upvotes: 0

Views: 605

Answers (1)

Federkun
Federkun

Reputation: 36934

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"]));

Upvotes: 2

Related Questions