2011-10-30 86 views
0

我將MYSQL數據庫中的圖像保存爲BLOB格式。當我嘗試獲取該圖像時,Web瀏覽器會要求我下載它。 我會問如何直接在瀏覽器中顯示圖像。如何在不下載的情況下在瀏覽器中顯示圖像?

以下是我使用的代碼:

<?php 
//$id = $_GET['id']; 
include_once 'D_B.php';// Connect to server and select database. 
$query = "SELECT `name`, `type`, `size`, `content` FROM `upload` WHERE `id`='1'"; 
$result = mysql_query($query) or die('Error, query failed'); 
list($name, $type, $size, $content) =mysql_fetch_array($result); 

header("Content-length: $size"); 
header("Content-type: $type"); 
header("Content-Disposition: attachment; filename=$name"); 
echo $content; 
exit; 
?> 

回答

3

取出內容處理標頭:header("Content-Disposition: attachment; filename=$name");和它應該很好地工作。

+0

謝謝..它運作良好。 – Aan

+2

@Adban:更改爲'header(「Content-Disposition:inline; filename = $ name」);'也會修復它,但保留文件名,這樣當Ctrl + S瀏覽器會自動填充該文件名而不是「download.php」等。 – Boann

相關問題