2014-02-12 28 views
1

我想用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>&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(); 
?> 

谢谢,任何帮助。我很欣赏任何反馈。

回答

1

总体规划

使用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> 

分配标记使用Adobe Acrobat和点他们

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

PDF存储在MySQL数据库中,而不是存储在我的FTP服务器中。 – Kelsey

+0

@迈克尔我知道这一点! – SteAp

+0

我的PHPmyAdmin网址是cp.freehostia.com,我用它来取代http://myServ.com? – Kelsey

0

你能做到这一点呢?

<a href='http://www.website-url.com/FolderName/{$row['name']}' > Open </a> 

文件夹名称是您的PDF文件存储的地方。
我认为{$ row ['name']}只是您的pdf的文件名。

+0

PDF文件未存储在文件夹中。它存储在我的网站的MySQL数据库中。我不想使用文件夹,但谢谢你。 – Kelsey

相关问题