gpt4 book ai didi

php - 从 mysql 数据库中检索为 blob 图像时图像损坏

转载 作者:行者123 更新时间:2023-11-28 03:13:21 25 4
gpt4 key购买 nike

我每次都得到损坏的图像。请帮助我,我是 php 的新手。 imagedata 是我的名为属性的表中的 blob 类型的列,我在文件 print.php 中的调用函数如下所示

/*This is image.php file*/
$servername = "localhost";
$username = "root";
$password = " ";
$dbname = "nevin";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if (!isset($_GET['id']))
{
//If not isset -> set with dumy value
$_GET['id'] = "undefine";
$id=mysql_real_escape_string($_GET['id']);
}
$image = mysql_query("SELECT * FROM property where id = '$id'");
if($image)
$image=mysql_fetch_assoc($image);
$image=$image['imagedata'];/*imagedata is column of blob type in my table named property*/
header('Content-Type: image/jpg');/* in my database i have images in jpg format and i am storing images as blob datatype*/
echo $image;
?>


<img src="image.php?id=<?php echo $row["id"]; ?>
/*this is my calling function in file print.php as shown below*/

/*print.php*/
<body>
<?php
$servername = "localhost";
$username = "root";
$password = " ";
$dbname = "Nevin";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT * FROM property";
$result = mysqli_query($conn, $sql);

?>


<section>
<div class="features">
<div class="l-container">
<div class="content-wrap clearfix align-center">


<?php



while($row = mysqli_fetch_assoc($result))
{

echo '<div class="grid">';?>
<img src="image.php? id=<?php echo $row["id"]; ?>" /><?php
echo '<h2>'.$row["id"].'</h2>'.
'<p>'. $row["city"]. " " . $row["price"].'</p>'.
'</div>';

}
?>
</div>
</div>
</div>
</section>
</body>

最佳答案

改变这个

<img src="image.php? id=<?php echo $row["id"]; ?>" />

<img src="image.php?id=<?php echo $row['id']; ?>"/>

关于php - 从 mysql 数据库中检索为 blob 图像时图像损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29443622/

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