gpt4 book ai didi

php - 如何在我的网页中显示Mysql中保存为Medium Blob的图片?

转载 作者:行者123 更新时间:2023-11-29 14:48:19 29 4
gpt4 key购买 nike

所以我在 HTML 中有这段代码:

 <img src="imagescript.php?id=1">

我在 imagescript.php 中有这段代码:

<?php
$servername="localhost";
$username="root";
$conn= mysql_connect($servername,$username)or die(mysql_error());
mysql_select_db("licitatii",$conn);
$sql="select picture from auctions where auction_id='$_GET[id]'";
$result=mysql_query($sql,$conn) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$image = $row['picture'];
header("Content-type: image/jpeg");
print $image;
?>

我已按照互联网上的说明使用了此功能,但我的图像未显示。

是否有可能我上传的图片不正确?

我在 method="POST"表单中使用 < input name="regphoto"type="file"> ,然后在表中插入 $_POST[regphoto]

如果对您有帮助,这是我在单击提交按钮后用来插入照片的 php 脚本:

$sql="插入拍卖 (auction_id,owner_id,parent_category_id,title,描述图片邮费起始价格购买价格结束日期 )values(NULL,'$ownerid','$parentcategoryid','$_POST[regtitle]','$_POST[regdescription]','$_POST[regphoto]','$_POST[regpostage]','$_POST [regstartingprice]','$_POST[regbuyoutprice]','$expiration')";

正如你所看到的,我在“图片”列(类型为mediumblob)中插入了值$_POST[regphoto]

最佳答案

一些可能有帮助的评论:

  1. 您可能需要使用密码登录 mysql 服务器(尽管不一定......)。
  2. 您需要保护您的代码免受 SQL 注入(inject)攻击,您的情况最简单的方法是 $id = (int) $_GET[id] 并使用 $id 在您的查询中。
  3. 您还必须发布用于插入图像的 php 代码,因为插入 $_POST[photo] 听起来不对:您需要 $_FILES['photo'] 这是一个数组,请参阅 manual .

关于php - 如何在我的网页中显示Mysql中保存为Medium Blob的图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6374398/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com