我已经将图像上传到数据库中,但是当我想显示它时,图像无法显示..我不知道为什么它无法显示..我的编码可能有问题..你能帮帮我吗?
上传.php
<?php
$id = $_POST['account'];
$code = $_POST['code'];
$price = $_POST['price'];
echo $file = $_FILES['image']['tmp_name'];
if (!isset($file))
echo "Please select an image.";
else
{
$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
{
if (!$insert = mysql_query("INSERT INTO menu
VALUES('$code','$price','$image','$id')"))
echo "Problem uploading images.";
else
{
$lastid = $code;
echo "Image uploaded.<p />Your image:<p /><img src=get.php?id=$lastid>";
}
}
}
?>
获取.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("food", $con);
$id = addslashes($_REQUEST['FoodId']);
$image = mysql_query("SELECT * FROM menu WHERE FoodId=$id");
$image = mysql_fetch_assoc($image);
$image = $image['image'];
header("Content-type: image/jpeg");
echo $image;
?>