直接从数据库显示图像

时间:2017-11-22 08:49:33

标签: php

显然我有显示图像的问题,因为它只显示文件的名称,无论如何它是否立即显示在网页上? 下面是我的源代码以及我的数据库的2个截图,其中包含图像以及我希望它显示在的位置:

<?php

error_reporting(E_ERROR); 

include("global.php");


session_start();

$receipt = $_GET['receipt'];
$userid = $_SESSION ['userid'];
if (isset($_SESSION['userid']) == false) 
{
    header ("Location: login.php");
}

$mysqli = new mysqli(spf, dbuser, dbpw, db);
$stmt = $mysqli->prepare("SELECT receipt, date, time, pick, dropoff, userid, carno, cost, branch, area, image FROM items where receipt=?");
$stmt->bind_param("s", $receipt);
$stmt->execute();
$stmt->bind_result($receipt, $date, $time, $pick, $dropoff, $userid, $carno, $cost, $branch, $area, $image);

while ($stmt->fetch()) {
    echo "<table border='1' style='width:40%'>";
    echo "<td>";
    echo "<b>Receipt ID: $receipt</b>";
    echo "<br><br>";
    echo "$image";
    echo "<br><br>";
    echo "<b>Date of Travel: $date</b>";
    echo "<br><br>";
    echo "<b>Time of Travel: $time</b>";
    echo "<br><br>";
    echo "<b>Pick Up Location: $pick</b>";
    echo "<br><br>";
    echo "<b>Drop Off Location: $dropoff</b>";
    echo "<br><br>";
    echo "<b>Area of DropOff: $area</b>";
    echo "<br><br>";
    echo "<b>Cost of Trip: $cost</b>";
    echo "<br><br>";
    echo "<b>User ID (NRIC): $userid</b>";
    echo "<br><br>";
    echo "<b>Branch of Officer: $branch</b>";
    echo "</td>";
}

echo "</table>";

$stmt->close();
$mysqli->close();

?>

预览: location where i want to display my image

An image file name inside the database

2 个答案:

答案 0 :(得分:3)

使用git config --global user.name "Z" git config --global user.email "z@email.com" 标记,如下所示

<img>

答案 1 :(得分:1)

试试这个:

echo "<img src='$image'>";

了解img