2015-04-04 126 views
2

我每次都會破碎圖像。請幫助我,這是我新的PHP。圖象 - 是我的表命名屬性BLOB類型的列,如下圖所示當從mysql數據庫中檢索到圖像時,圖像被破壞

/*This is image.php file*/ 
$servername = "localhost"; 
$username = "root"; 
$password = " "; 
$dbname = "nevin"; 

// Create connection 
$conn = mysqli_connect($servername, $username, $password, $dbname); 
// Check connection 
if (!$conn) { 
die("Connection failed: " . mysqli_connect_error()); 
} 
if (!isset($_GET['id'])) 
{ 
//If not isset -> set with dumy value 
$_GET['id'] = "undefine"; 
$id=mysql_real_escape_string($_GET['id']); 
} 
$image = mysql_query("SELECT * FROM property where id = '$id'"); 
if($image) 
$image=mysql_fetch_assoc($image); 
$image=$image['imagedata'];/*imagedata is column of blob type in my table  named property*/ 
header('Content-Type: image/jpg');/* in my database i have images in jpg format and i am storing images as blob datatype*/ 
echo $image; 
?> 


<img src="image.php?id=<?php echo $row["id"]; ?> 
/*this is my calling function in file print.php as shown below*/ 

/*print.php*/ 
<body> 
<?php 
$servername = "localhost"; 
$username = "root"; 
$password = " "; 
$dbname = "Nevin"; 

// Create connection 
$conn = mysqli_connect($servername, $username, $password, $dbname); 
// Check connection 
if (!$conn) { 
die("Connection failed: " . mysqli_connect_error()); 
} 

$sql = "SELECT * FROM property"; 
$result = mysqli_query($conn, $sql); 

?> 


<section> 
    <div class="features"> 
    <div class="l-container"> 
    <div class="content-wrap clearfix align-center"> 


     <?php 



     while($row = mysqli_fetch_assoc($result)) 
     { 

     echo '<div class="grid">';?> 
      <img src="image.php? id=<?php echo $row["id"]; ?>" /><?php 
      echo '<h2>'.$row["id"].'</h2>'. 
      '<p>'. $row["city"]. " " . $row["price"].'</p>'. 
      '</div>'; 

      } 
?>    
    </div> 
</div> 
</div> 
</section> 
</body> 

+0

檢查此鏈接:-http://stackoverflow.com/questions/25209913/how-do-i-display-images-stored-as-blob-da TA型在MySQL的與 - PHP – 2015-04-04 06:57:44

回答

0

更改文件print.php我的調用函數這個

<img src="image.php? id=<?php echo $row["id"]; ?>" /> 

<img src="image.php?id=<?php echo $row['id']; ?>"/> 
相關問題