0

嘿,我在 php 中显示图像时遇到问题。图像被存储在 mysql 的表“图像”中。还有另一个表'restaurant'需要获取这些图像并根据restid显示相应的图像。但是,它在获取图像而不显示它们时面临问题。请帮忙!这是 imageupload.php:

<?php
require 'connect.inc.php';
?>
<html>
<head>
<title>Uploading image</title>
</head>
<body>
<?php
echo "<form action='imageupload.php' method='POST' enctype='multipart/form-data'>

Upload: <input type='file' name='image'><input type='submit' value='Upload' >
</form>";

if(isset($_FILES['image']['tmp_name']))

{
    $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
    $image_name = addslashes($_FILES['image']['name']);
    $image_size = getimagesize($_FILES['image']['tmp_name']);
    if($image_size==FALSE)
        echo "That's not an image";
    else
    {
        $query = "INSERT INTO images VALUES ('','$image_name','$image','22')";
        $result = mysqli_query($con, $query);

        if(!$result)
        {
            echo "Problem uploading";

        }
        else
        {
            echo "Image uploaded ";
            $query2 = "SELECT * FROM images WHERE restid = '22'";
            $result2 = mysqli_query($con,$query2);
            while($info = mysqli_fetch_array($result2))
            {
                header("Content-type: image/jpeg");
                echo $info['image'];
            }
        }
    }
}
else
{
    "Please upload a file";
}
 ?>
</body></html>

这是 getimage.php (它获取图像并显示它):

<?php
require 'connect.inc.php';
$id = $_REQUEST['id'];
$image = "SELECT * FROM images WHERE imgid = $id" ;
$image = mysqli_query($con, $image);
$image = mysqli_fetch_assoc($image);
$image = $image['image'];

header("Content-type: image/jpeg");
echo $image;
?>

connect.inc.php 是一个连接数据库的文件。我提到了其他链接,但没有得到任何可靠的帮助。请提供帮助。

4

1 回答 1

0

在 mysql 中存储图像应该可以工作。检查您是否有任何语法错误。临时删除 Content-type 标头以查看图像文件被打印(作为乱码字符串)。还要检查您存储图像的 mysql 字段是否为 BLOB 类型。如果您有任何错误,请发布。

于 2013-09-22T19:53:21.777 回答