gpt4 book ai didi

php - 显示 BLOB 数据

转载 作者:行者123 更新时间:2023-11-30 01:36:19 25 4
gpt4 key购买 nike

我需要显示 BLOB 数据。list_files.php

<?php
// Connect to the database
$dbLink = new mysqli('127.0.0.1', 'root', '', 'db_name');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}

// Query for a list of all existing files
$sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`';
$result = $dbLink->query($sql);

// Check if it was successfull
if($result) {
// Make sure there are some files in there
if($result->num_rows == 0) {
echo '<p>There are no files in the database</p>';
}
else {
// Print the top of a table
echo '<table width="100%">
<tr>
<td><b>Name</b></td>
<td><b>Mime</b></td>
<td><b>Size (bytes)</b></td>
<td><b>Created</b></td>
<td><b>&nbsp;</b></td>
</tr>';

// Print each file
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>{$row['name']}</td>
<td>{$row['mime']}</td>
<td>{$row['size']}</td>
<td>{$row['created']}</td>
<td><a href='get_file.php?id={$row['id']}'>Download</a></td>
</tr>";
}

// Close table
echo '</table>';
}

// Free the result
$result->free();
}
else
{
echo 'Error! SQL query failed:';
echo "<pre>{$dbLink->error}</pre>";
}

// Close the mysql connection
$dbLink->close();
?>

这是我显示数据的代码。输出是

Name            Mime              Size (bytes)             Created   
cubeatwork.jpg image/jpeg 38717 2013-05-29 16:45:17 Download
9cube.jpg image/jpeg 23187 2013-05-30 10:08:37 Download

但我需要显示图像而不是这些数据。怎么做。请帮助我

最佳答案

在将其打印为图像之前,您需要指定标题。就像循环中的以下代码一样。

header('内容类型:image/jpeg');

或者

header('内容类型:'.$row['mime']);

echo $row['size'];//如果“size”是 blob 类型

希望这对你有帮助

关于php - 显示 BLOB 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16828765/

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