2015-11-05 59 views
1

試圖在數據庫與此廣東話顯示圖像的PHP

$file = $_FILES['image']['tmp_name']; 
$image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); 
$image_name = addslashes($_FILES['image']['name']); 
$image_size = getimagesize($_FILES['image']['tmp_name']); 

if($image_size == false) 
{ 
    echo "Not an image"; 
} 
else 
{ 
    mysqli_query($link, "INSERT into Events (imagetype, Attachments) 
         VALUES ('$image_name', '$image')"); 
} 

connection.php到uploadimage包括我的連接

嘗試與該檢索圖片:

include "connection.php"; 

$query = "SELECT imagetype,Attachments from Events where E_id='$id' "; 
$result = mysqli_query($link,$query); 
while ($row = mysqli_fetch_assoc($result)) 
{ 
    header("Content-type:image/jpeg"); 
    echo mysqli_result($row['Attachments'], 0); 
} 
+0

你進入「圖像」 - ''image''字符串,而不是預期的變量。 –

+0

你能告訴我具體在哪裏 –

+2

我已經有了。除非這是一個壞的粘貼 –

回答

1

這是你的錯誤。

在你的代碼中,echo mysqli_result($row['Attachments'], 0);在這一行中,我不清楚你爲什麼使用mysqli_result

如果您的Attachments的數據類型是VARCHAR,我認爲$row['Attachments']就足夠了。

所以你對顯示圖像的代碼應該是

while($row= mysqli_fetch_assoc($result)){ 
    header("Content-type:image/jpeg"); 
    echo ($row['Attachments']);