[英]unable to display my images stored in the database
i want to display all the images stored in the database.. then my problem is that only small square will appear.. i need help.. 我想显示存储在数据库中的所有图像..那么我的问题是只会出现一个小方块..我需要帮助..
my maincontent.php 我的maincontent.php
<?php
error_reporting(E_ALL);
$link = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
mysql_select_db("login") or die(mysql_error());
$sql = "SELECT id FROM products";
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
while($row=mysql_fetch_assoc($result)){
echo '<img src="t2.php?id='.$row['id'].'"/>';
}
mysql_close($link);
?>
my t2.php 我的t2.php
<?php
error_reporting(E_ALL);
if(isset($_GET['id']) && is_numeric($_GET['id'])) {
$link = mysql_connect("localhost", "root", "") or die("Could not&nbsp;connect: " . mysql_error());
mysql_select_db("login") or die(mysql_error());
$sql = "SELECT photo FROM products WHERE id={$_GET['id']}";
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
header("Content-type: image/jpeg");
echo mysql_result($result, 0);
mysql_close($link);
}else{
echo 'Please use&;nbsp;a real id number';
}
?>
i hope someone can help me regarding this problem. 我希望有人可以帮助我解决这个问题。
I do not know how you saved your image in your database(direct images or image path). 我不知道您如何将图像保存在数据库中(直接图像或图像路径)。 but it seems that you have to be changed those: 但似乎您必须更改以下内容:
Change this line : 更改此行:
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
to: 至:
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
and your t2.php 和你的t2.php
Change : 变更:
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
to : 至 :
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
you need to use mysqli_*
or PDO
. 您需要使用mysqli_*
或PDO
。 mysql_*
all functions are deprecated. mysql_*
不推荐使用所有功能。
Change to this. 改成这个。 your t2.php 您的t2.php
<?php
$imageId = intval($_GET["id"]);
$query = mysql_query("SELECT img FROM images WHERE id = ". $imageId);
$row = mysql_fetch_array($query);
$mime = null;
// place $type init. here
if ($type=="pjpeg") // <<< where do you get $type btw?
$mime = "image/jpeg";
$b64Src = "data:".$mime.";base64," . base64_encode($row["img"]);
echo '<img src="'.$b64Src.'" alt="" />';
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.