簡體   English   中英

如何在img src標簽中調用php?

[英]How to call php in img src tag?

這是我的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>

這是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);
?>

結果如下:

在此處輸入圖片說明

使用php/imageView.php?ID=<?php echo $row["ID"]我得到了文件的路徑:

uploads/film/pic/5.jpg

為什么不顯示圖像?

為什么不顯示圖像?

因為php/imageView.php?ID=<?php echo $row["ID"];?>返回圖像的路徑,而不返回圖像本身。

imageView.php可以采用該路徑並將用戶代理重定向到該路徑:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM