2016-10-21 8 views
-2

I can't find any syntax or logical error in this code, but i don't why the image is not being displayed on the web page, also it is not showing any error,i'm sharing the code and the output that i'm getting. If you can help me in displaying image, i'll be very thankful to you.디스플레이 이미지는

Output on the Web Page

<html> 
<body> 
<?php 

$servername = "localhost"; 
$username = "root"; 
$password = ""; 
$dbname = "CSE"; 

// Create connection 
$conn = new mysqli($servername, $username, $password, $dbname); 
// Check connection 
if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 
} 

$query = "SELECT * FROM upload WHERE id=1"; 
$result = $conn->query($query); 
while($row = $result->fetch_assoc()) 
{ 

    header("Content-Type: image/png"); 
    echo '<img height="300" width="300" alt="logo" src="data:image;base64,'.$row["name"].'">'; 
} 
$conn->close(); 


?> 

</body> 
</html> 
+2

먼저 헤더 선언을 제거하십시오. 브라우저에 이미지를 출력하지 않고 HTML을 출력합니다. 이미 콘텐츠를 브라우저에 보낸 후에는 헤더를 보낼 수 없습니다. –

+2

그리고 당신이 보았던 것은 PHP 파일이었습니다. – csmckelvey

답변

1

첫째, 헤더를 제거합니다. HTML 만 출력합니다. 이미지가 아니라 이미 HTML을 브라우저에 전송 했으므로 이후에 추가 헤더를 보낼 수 없습니다.

그런 다음 당신은베이스 64에 BLOB 데이터 (바이너리 데이터)로 변환해야합니다

같은 페이지에 이미지를 인라인으로 보여주는입니다
while($row = $result->fetch_assoc()) 
{ 
    echo '<img height="300" width="300" alt="logo" src="data:' . $row["type"] . ';base64,'.base64_encode($row["name"]).'">'; 
} 

.

편집 : 더 동적으로 만들려면 데이터베이스에서 "유형"을 추가하십시오. (당신이 그것을 구했기 때문에).

+0

웹 페이지의 결과물이 아닙니다. 고맙습니다. –

+0

데이터베이스에서 "type"을 추가하여 동적으로 만들었습니다. –

+0

다시 감사 :-) –