2013-10-08 53 views
1

我創建了一個使用phpmyadmim的數據庫並訪問它,我創建了一個name.php文件。如何檢索通過php存儲在數據庫中的圖像?

訪問註冊號,名稱很容易,但圖像檢索不是這樣的。 我通過使用LongBlob作爲類型存儲圖像通過phpmyadmin ..但我無法顯示它..

如何檢索圖像?

如果有人可以幫忙,請高度讚賞。

感謝, LJ

<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>PHYTOCHEMICAL DB</title> 
     <style type="text/css"> 
      body { 
       font-family: Georgia, "Times New Roman", 
        Times, serif; 
       color: purple; 
       background-color: #EEEEEE} 
      </style> 
     </head> 
     <body> 
      <table width="800" border="" align="center"> 
       <tr> 
       <td colspan="2" style="background-color:#FFA500;height:30px;width:700px"> 
        <div> <img src="leaves.jpg" height="300" width="900"/> </div> <br/> 
       </td> 
      </tr> 
      <tr> 
       <td style="background-color:#FFD700;width:250px;"> 
        <b>Menu</b><br> 
        <i> <a href="home.php">Home</a><br> 
         <i> <a href="did.php">Search by Database ID (DID)</a> <br> 
          <i><a href="mw.php">Search by Molecular weight<br> 
            </td> 

           <td style="background color:#EEEEEE;height:500px;width:800px;"> 
             <form action="" method="POST"> 
              <p> Enter the name </p> 
              <input type="text" name="pname"> 
              <input type="submit" value="submit" name="submit1"> 
              <br> 
             </form> 
             <?php 
             $mysqli = new mysqli("localhost", "root", "osddosdd", "phychem"); 
             if (mysqli_connect_errno()) { 
              printf("Connect failed:%s\n", mysqli_connect_error()); 
              exit(); 
             } 
             if (isset($_POST['submit1'])) { 
              $pname = $_POST['pname']; 
              $query = ("select * from pchem where name LIKE '$pname'"); 
              $result = $mysqli->query($query); 
              echo 'The retrieved query is:'; 
              echo "<table border='1'> 
     <tr> 
      <th>DID</th> 
      <th>Name</th> 
      <th>Molecular weight</th> 
     </tr>"; 
              while ($row = $result->fetch_row()) { 
               echo '<tr>'; 
               printf("<th>%d</th> <th> %s </th> <th> %2f </th>", $row[0], $row[1], $row[2]); 
               echo '</tr>'; 
               echo '</table>'; 
              } 
             } 
             $mysqli->close(); 
             ?> 
</td> 
            </table> 
            </body> 
            </html> 
+5

永遠不要存儲圖像數據庫裏面,在數據庫中存儲的名字和形象的路徑和圖像存儲在文件系統中。 –

+0

您是否嘗試過?爲什麼你需要將圖像存儲到數據庫中?你可以將其存儲在目錄中..只需將圖像路徑保存到數據庫 – Ashish

+0

如上所述,不好存儲,但如果你必須: - > http://stackoverflow.com/questions/8289451/php-image-retrieval- from-mysql-blob-directly-into-img-tag –

回答

0

不將圖像直接存儲到數據庫爲BLOB。只需將它們作爲文件存儲並僅將文件名存儲在數據庫中。

+0

同時通過phpmyadmin將圖像存儲到mysql,它要求選擇文件,,這是給圖像路徑的方式?? 並且在給出這個路徑之後,在.php頁面中添加什麼代碼? – learntocode

相關問題