2014-02-23 26 views
0

我有一個代碼,用於檢查用戶是否將圖像上載到數據庫,並且該圖像是作爲Blob類型存儲的。如果用戶沒有上傳任何圖像,它將使用默認圖像作爲背景。我一直在嘗試不同類型的代碼,這些代碼在這裏不工作是我的代碼。檢查Blob圖像並將其用作背景

$backimage = $row2['back_img']; 

if($backimage<=0){ 
$background = "images/main-wrapper-bg.png"; 


} 
else 
{ 
$background = 'data:image/png;base64,'.base64_encode($row2['back_img']); 
} 

這裏是背景

body { 
margin: 0; 
padding: 0; 
background: url(<?php echo $background;?>); 
background-position:center top; 
background-repeat: repeat; 

font-family: Arial; 
font-size: 14px; 

} 
+0

'$ backimage <= 0'應該是'empty($ backimage)'你也應該檢查一下它的圖片http://ca3.php.net/imagecreatefromstring –

+0

@LozCherone這就像一個魅力。非常感謝!你的答案幫助了我! – bjmonts

回答

0

你可以嘗試移動背景樣式的身體在HTML這樣我的CSS代碼:

<html> 
<body style="background-image:url(<?php echo $background;?>)"> 
blah blah 
</body> 
</html> 

如果這不工作,嘗試echo $background,在if/else之後。在這裏發佈它輸出的內容。