在mysql数据库中显示路径中的图像

时间:2014-06-19 03:06:56

标签: mysql

我正在尝试了解如何从存储在mysql数据库中的路径中检索图像。我有充当图像的路径

这是我到目前为止尝试过的代码。

<?php include 'database.php'; ?>
   <!Doctype html>
<html>
<head>
    <title>The Image</title>
</head>
<body>
    <?php
        $sql = 'Select * from images';
        $result = mysql_query($sql) or die('Crazy man');

        while($row = mysql_fetch_assoc($result))
        {
            $url = 'http://localhost/image_path/'. $row[image_path];
            echo "<img src='$url' height='200' width='200' />";
        }
    ?>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

根据您的代码

while($row = mysql_fetch_assoc($result))
    {
        $url = 'http://localhost/image_path/'. $row[image_path];
        echo "<img src='$url' height='200' width='200' />";
    }

我认为您需要将其更改为此类

while($row = mysql_fetch_assoc($result))
    {
        $url = 'image_path/'. $row[image_path];
        echo "<img src='$url' height='200' width='200' />";
    }

请注意我删除了http://localhost/

$url = 'http://localhost/image_path/'. $row[image_path];

每当您尝试加载图片时,都会自动加载默认目录,这样您就可以直接放置 / image_path / blah-blah