2012-03-13 24 views
0

我正在創建一個Web應用程序,用戶可以在其中上載/下載/查看在線PDF。我想更改PDF文件的名稱以在新標籤鏈接中查看(就像我們在所有網站中看到的一樣)。在PHP中查看PDF鏈接

有誰知道如何讓數據庫中的任何字段提供一個鏈接,當用戶點擊時,它打開一個新的標籤中的PDF?

if($result) { 
    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>type</b></td> 
        <td><b>Size (bytes)</b></td> 
        <td><b>Created</b></td> 
        <td><b>&nbsp;</b></td> 
        <td><b>view><b/></td> 
       </tr>'; 

     // Print each file 
     while($row = $result->fetch_assoc()) { 
      echo " 
       <tr> 
        <td>{$row['name']}</td> 
        <td>{$row['type']}</td> 
        <td>{$row['size']}</td> 
        <td>{$row['created']}</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(); 
+0

向我們展示來自'$ row'的示例數據 – webbiedave 2012-03-13 19:39:11

回答

2

該解決方案不一定在數據庫內。

您可以使用一個錨標記,以將用戶重定向到鏈接:

<a href="{$path_to_pdf}" target="_blank" >Click here to view the PDF</a>
將在表中的單元格您正在生成。


我可能會被誤認爲 - 但我確實認爲用戶瀏覽器也是一個因素。瀏覽器必須能夠顯示pdf。最新的和最偉大的*瀏覽器已經推出,但用戶偏好'也可能是一個因素。

* Let your imagination run wild

0

當輸出鏈接到PDF,使用此:

<a href="http://www.stackoverflow.com" target="_blank">Visit StackOverflow</a> 

設定目標將告訴瀏覽器在新標籤頁中打開鏈接。