2013-10-08 46 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

相关问题