如何显示imaget存储在数据库中

时间:2015-06-09 09:03:20

标签: php sql

我没有收到我存储在数据库中的任何图像。图像的路径存储在数据库中。但是当我试图获取图像时,它会显示一个空白页面。\

注意:我想要显示图像和文字。所以请不要写标题。

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db_dat";

$s='';
$conn = mysqli_connect($servername, $username, $password, $dbname);

$uploadDir = 'C:\wamp\www\images\passport images';

$sql = "SELECT * from upload2 ";
$result = $conn->query($sql);
    while($row = $result->fetch_assoc()) {
        echo '<img src=  "'.$uploadDir.'" ."'.$row['name'].'">' ;
}



 ?>

`

1 个答案:

答案 0 :(得分:1)

试试这个

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db_dat";

$s='';
$conn = mysqli_connect($servername, $username, $password, $dbname);

$uploadDir = 'http://localhost/images/passport images';

$sql = "SELECT * from upload2 ";
$result = $conn->query($sql);
    while($row = $result->fetch_assoc()) {
        echo '<img src=  "'.$uploadDir.'" /"'.$row['name'].'">' ;
}



 ?>