我在访问我在sql表add_deal中保存为Long BLOB类型的图像时遇到问题,我面临的问题是我无法访问图像并在浏览器中显示它。当我运行程序时,我看到一个破碎的页面。我试过放置“header('Content-type:image / jpeg');”上面的回声反过来给出一个错误,指出“因为它包含错误而无法显示图像”我将图像保存为:
$image = addslashes($_FILES['image']['tmp_name']);
$name=addslashes($_FILES['image']['name']);
$image_size=getimagesize($_FILES['image']['tmp_name']);
$deal_type = $_POST['dealtype'];
$description = $_POST['description'];
$quantity = $_POST['quantity'];
$validity = $_POST['validity'];
$price=$_POST['cost'];
$qry="INSERT INTO `add_deal`(`dealtype`, `description`, `quantity`, `validity`, `price`, `image`, `name`) VALUES ('$deal_type','$description','$quantity','$validity','$price','$image','$name')";
$result=mysqli_query($db,$qry);
if(! $result ) {
die("Query FAILED. " . mysqli_error($db));
}
else
{
echo "Your Deal has been placed in your Gallery";
echo "<br/>Go to <a href='dealhome.php'>home</a> page to see whats in your gallery</b>";
}
并将其作为:
访问 if(! $result ) {
die("Query FAILED. " . mysqli_error($db));
}
else
{
if ($result->num_rows > 0) {
// output data of each row
//echo "<table>";
while($row = mysqli_fetch_row($result)) {
header('Content-type: image/jpeg');
echo $row['image'];
}
}
//echo "</table>";
}