2010-06-26 108 views
0

當我試圖從數據庫中顯示圖像圖像未顯示不知道是什麼問題,這是我的代碼。無法顯示圖像

show_desc.php

<?php 
    $errmsg = ""; 

    if (! @mysql_connect("localhost","root","")) { 
    $errmsg = "Cannot connect to database"; 
    } 

    @mysql_select_db("dbname"); 

    if (isset($_GET['img_name'])) { 
    $gotten = @mysql_query("select img from image where img_id = ".$_GET['img_name']); 

    header("Content-type: image/x-ms-bmp"); 

    while ($row = mysql_fetch_array($gotten)) { 
     print $row['img']; 
    } 
    mysql_free_result($gotten); 
    } 
    ?> 

Display.php的

<?php 
    $errmsg = ""; 

    if (! @mysql_connect("localhost","root","")) { 
     $errmsg = "Cannot connect to database"; 
    } 

    @mysql_select_db("dbase_mgb"); 

    $strSQL = "select * from image"; 
    $rsPix = mysql_query($strSQL); 
    $numRows = mysql_numrows($rsPix); 

    $i = 0; 

    while($i < $numRows) { 
    ?> 

    <image src="show_desc.php?img_id=<?php echo mysql_result($rsPix,$i,"img_id"); ?>" 

    <?php 

    $i++; 

    } 
    ?> 

任何人都可以請幫助我?

回答

1
  1. 您的display.php似乎沒有生成正確的<img>標籤。
  2. 檢查在數據庫中的IMG字段被標記爲BINARY
+0

這個論壇是不是讓我把圖像標籤,它是while條件後,即使在數據庫中的IMG字段被標記不顯示圖像作爲二進制 – Shruti 2010-06-26 13:55:42

0

爲什麼你堅強的圖像到數據庫?將圖像的名稱/路徑簡單地保存到數據庫中,將它們上傳到文件夾並在<img>標籤中檢索它們的名稱時顯示它們會更好。

+0

這意味着他們不會被捕獲在一個mysqldump中,並具有巨大的斷開/缺乏參照完整性的風險 – 2010-06-26 13:53:44

+0

你能告訴我怎麼做,謝謝 – Shruti 2010-06-26 13:58:08

+0

@Shruti:看到這個主題plz :http://stackoverflow.com/questions/450876/upload-image-to-server-using-php-store-file-name-in-a-mysql-database-with-other – Sarfraz 2010-06-26 14:01:57

1

我的事情你使用圖像數據類型爲BLOB