嘿,我在 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 是一个连接数据库的文件。我提到了其他链接,但没有得到任何可靠的帮助。请提供帮助。