2014-03-25 2 views
0

내가 데이터베이스에 저장된 모든 이미지를 표시 할 데이터베이스에 저장된 표시 할 수 없습니다 .. 다음 내 문제는 작은 사각형이 .. 저 좀 도와주세요 ..내 이미지

내 maincontent.php 나타날 것입니다

<?php 
    error_reporting(E_ALL); 
    $link = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error()); 
    mysql_select_db("login") or die(mysql_error()); 
    $sql = "SELECT id FROM products"; 
    $result = mysql_query("$sql") or die("Invalid query: " . mysql_error()); 
    while($row=mysql_fetch_assoc($result)){ 
    echo '<img src="t2.php?id='.$row['id'].'"/>'; 
    } 
    mysql_close($link); 
     ?> 

내 t2.php는

<?php 
error_reporting(E_ALL); 
if(isset($_GET['id']) && is_numeric($_GET['id'])) { 

$link = mysql_connect("localhost", "root", "") or die("Could not&amp;nbsp;connect: " . mysql_error()); 

mysql_select_db("login") or die(mysql_error()); 

$sql = "SELECT photo FROM products WHERE id={$_GET['id']}"; 

$result = mysql_query("$sql") or die("Invalid query: " . mysql_error()); 

header("Content-type: image/jpeg"); 
echo mysql_result($result, 0); 
mysql_close($link); 
}else{ 
echo 'Please use&;nbsp;a real id number'; 

} 
?> 

나는 누군가가이 문제에 관한 나를 도울 수 있기를 바랍니다.

+0

메신저 데이터베이스에서 이미지를 저장하는 데 BLOB를 사용합니다. 결과는 다음과 같습니다 : https://dl.dropboxusercontent.com/u/87636874/Capture.JPG – user2699948

+0

브라우저에서't2.php? id = SOMEID'를 수동으로 열면 무엇을 얻게됩니까? 에러를 위해서'echo'를 사용하고 있기 때문에'' 태그 안에 그것들을 볼 수 없기 때문에 이것을 검사해야합니다. –

+0

오류가 발견되지 않습니다. BLOB가 올바르게 저장 되었습니까? 몇 줄에 mysqldunp를 제공 할 수 있습니까? – blue

답변

-1

변경하십시오. 당신의 t2.php

<?php 
    $imageId = intval($_GET["id"]); 

    $query = mysql_query("SELECT img FROM images WHERE id = ". $imageId); 
    $row = mysql_fetch_array($query); 

    $mime = null; 
    // place $type init. here 
    if ($type=="pjpeg") // <<< where do you get $type btw? 
     $mime = "image/jpeg"; 

    $b64Src = "data:".$mime.";base64," . base64_encode($row["img"]); 
    echo '<img src="'.$b64Src.'" alt="" />'; 
    ?> 
+0

어떻게하면 'echo'를 사용하여 이미지를 표시하는 데 도움이 될 것입니까 '; –

+0

그래, 나는이 것을 갱신 할 예정이었다 .... [email protected]을 지적 해 주셔서 고마워요. – Abhishek

0

나는 당신이 당신의 데이터베이스 (직접 이미지 나 이미지 경로)에 이미지를 저장 방법을 모르겠어요.

변경이 라인 :

$result = mysql_query($sql) or die("Invalid query: " . mysql_error()); 

에 :

$result = mysql_query($sql) or die("Invalid query: " . mysql_error()); 

하고 t2.php

변경 :

$result = mysql_query($sql) or die("Invalid query: " . mysql_error()); 
그러나 당신이 그 변경해야 할 것으로 보인다

~ :

$result = mysql_query($sql) or die("Invalid query: " . mysql_error()); 

당신은 mysqli_* 또는 PDO을 사용해야합니다. mysql_* 모든 기능이 사용되지 않습니다.