2014-02-12 29 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

相關問題