<分区>
我制作了一个 php 页面,您可以在其中上传图像/文件,这些图像/文件将作为“mediumblob”类型保存在我的数据库中。现在我卡住了,无法弄清楚如何从数据库中显示这些图像。我在要打印图像的地方写了大写字母。
<?php
$dbLink = new mysqli('127.0.0.1', 'root', '', 'test');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
$sql = 'SELECT `id`, `name`, `mime`, `size`, `created`, `data` FROM `file`';
$result = $dbLink->query($sql);
if($result) {
// Kolla om det finns några filer i databasen
if($result->num_rows == 0) {
echo '<p>There are no files in the database</p>';
}
else {
echo '<table width="100%">
<tr>
<td><b>Name</b></td>
<td><b>Mime/type</b></td>
<td><b>Size (bytes)</b></td>
<td><b>Created</b></td>
<td><b>Image</b></td>
</tr>';
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>{$row['name']}</td>
<td>{$row['mime']}</td>
<td>{$row['size']}</td>
<td>{$row['created']}</td>
//THIS IS WHERE I'M SUPPOSED TO PRINT OUT THE IMAGES
</tr>";
}
echo '</table>';
}
}
else
{
echo 'Error! SQL query failed:';
echo "<pre>{$dbLink->error}</pre>";
}
echo '<p>Click <a href="index.html">here</a> to go back</p>';
// Close the mysql connection
$dbLink->close();
?>
这是我在数据库中的表:
CREATE TABLE `file` (
`id` Int Unsigned Not Null Auto_Increment,
`name` VarChar(255) Not Null Default 'Untitled.txt',
`mime` VarChar(50) Not Null Default 'text/plain',
`size` BigInt Unsigned Not Null Default 0,
`data` MediumBlob Not Null,
`created` DateTime Not Null,
PRIMARY KEY (`id`)
)
非常感谢任何帮助!