将参数传递给包含在 IMG 标签中的 PHP 文件

Und*_*e2k 2 php mysql

我有两个文件 [Main.html] 和 [image.php]。然而,[image.php] 正在处理二进制数据,因为它显示来自数据库的图像。我的问题是我可以,如果我可以,我如何将参数从 main 传递到 [image.php]?

我像这样在 main 中调用 image.php:

img src="image.php" alt="从数据库中检索的图像"

<?php
$mysqli=mysqli_connect('localhost','root','','draftdb');
if (!$mysqli)
die("Can't connect to MySQL: ".mysqli_connect_error());


    $stmt = $mysqli->prepare("SELECT display.PICTURE_ID 
    FROM cards  
    INNER JOIN display ON cards.DISPLAY_ID = display.DISPLAY_ID 
    WHERE display.DISPLAY_ID=? AND cards.CARD_TYPE =?" );

     if( rand(1, 8) == 8) 
     {
     $cardtype='Mythic';
     $displayid=rand(1,15) ;

     }

     else
     {
     $cardtype='Rare';
    $displayid=rand(16,19) ;
     }

    $stmt->bind_param("si", $displayid, $cardtype);
    $stmt->execute();
    $stmt->bind_result($image);
    $stmt->fetch();
    header("Content-Type: image/jpeg");
    echo $image; 
    ?>
Run Code Online (Sandbox Code Playgroud)

Lei*_*igh 5

在这里很难做出真正详细的答案,因为最简单的解决方案很好......简单。

您肯定已经看到带有?var=value&var2=anothevalue在其中的网站地址

你可以自己做同样的事情。

<img src="image.php?param=wat&moreparam=lolz" />

$param = isset($_GET['param']) ? $_GET['param'] : null;