我想用PHP創建一個鏈接,從我的MySQL數據庫表中打開一個PDF文件。 PDF文件已存儲在Sql表中我只是不確定如何用錨標記打開它。如何使用錨標記打開存儲在MySQL表中的PDF文件
該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> </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();
?>
謝謝,任何幫助。我很欣賞任何反饋。
PDF存儲在MySQL數據庫中,而不是存儲在我的FTP服務器中。 – Kelsey
@邁克爾我知道這一點! – SteAp
我的PHPmyAdmin網址是cp.freehostia.com,我用它來取代http://myServ.com? – Kelsey