【发布时间】:2020-11-26 23:34:01
【问题描述】:
我有这个项目,我应该插入和选择图片,就像上传和查看它们一样。最初,当我尝试代码时,它可以工作,但图像没有显示。经过多次试验,我只是从一个为他工作的伙伴那里复制了一个代码,但是当我尝试时,它没有。为什么?我已经在下面发布了所有内容-
图片上传代码
<head>
<title>Retrieve Image</title>
</head>
<body>
<h1>Retrieving Image from database using PHP</h1>
<table border="1px" >
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Image</th>
</tr>
</thead>
<?php
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"olap");
$query = "SELECT * FROM `blobclob`";
$query_run = mysqli_query($connection,$query);
while($row = mysqli_fetch_array($query_run))
{
?>
<tr>
<td> <?php echo $row['id']; ?></td>
<td> <?php echo $row['name']; ?></td>
<td> <?php echo '<img
src="data:image;base64,'.base64_encode($row['image']).' " alt="FlowerImage"
style="width:100px; height:100px;">'; ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
图像查看代码
<html>
<head>
<title>Retrieve Image</title>
</head>
<body>
<h1>Retrieving Image from database using PHP</h1>
<table border="1px" >
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Image</th>
</tr>
</thead>
<?php
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"olap_exp");
$query = "SELECT * FROM `images`";
$query_run = mysqli_query($connection,$query);
while($row = mysqli_fetch_array($query_run))
{
?>
<tr>
<td> <?php echo $row['id']; ?></td>
<td> <?php echo $row['name']; ?></td>
<td> <?php echo '<img
src="data:image;base64,'.base64_encode($row['image']).' " alt="FlowerImage"
style="width:100px; height:100px;">'; ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
输出
数据库
【问题讨论】:
-
提示:查看 HTML 源代码。也使用错误检查。
-
如何使用错误检查?
-
ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL);用于 PHP,mysqli_error($connection)用于查询。 -
您有什么特别的原因可以通过将图像二进制存储在数据库中来使事情变得更加困难吗?文件系统非常适合数据库上的文件。
-
那么,HTML 源代码揭示了什么和错误检查,你没有说。
标签: php html mysql image xampp