gpt4 book ai didi

php - 如何使用 anchor 标记打开存储在 MySQL 表中的 PDF 文件

转载 作者:行者123 更新时间:2023-11-29 00:19:15 25 4
gpt4 key购买 nike

我正在尝试使用 PHP 创建一个链接,从我的 MySQL 数据库表中打开一个 PDF 文件。 PDF 文件已存储在 Sql 表中,我只是不确定如何使用 anchor 标记打开它。

PDF 名为“a26ea542-b307-4cd6-9f62-7ba04831a0f1.pdf”。

这是我的 PHP 页面代码:

<?php
// Connect to the database
$dbLink = new mysqli('aaa', 'aaa', 'aaa', 'aaa');
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='{$row['name']}'>Open</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();
?>

感谢您的帮助。感谢任何反馈。

最佳答案

总体规划

使用 PHP 脚本 A.php,生成一个 HTML 页面,其中包含指向另一个脚本 someScript.php 的链接。第二个脚本生成 PDF。

要链接到 someScript.php 生成的 PDF 的第 3 页,请使用如下链接:

  • http://myServ.com/someScript.php#page=3

将 myServ.com 替换为您服务器的 DNS 名称。

将 PDF 发送到浏览器

header('Content-type: application/pdf');
readfile('a26ea542-b307-4cd6-9f62-7ba04831a0f1.pdf');

链接到部分 PDF

指向 pdf 的页面:

<a href="http://myServ.com/someScript.php#page=3">
Points to page 3
</a>

使用 Adob​​e Acrobat 分配标记并指向它们:

<a href="http://myServ.com/someScript.php#nameddest=Marker3">
Point to Marker3
</a>

关于php - 如何使用 anchor 标记打开存储在 MySQL 表中的 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21742348/

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