从mysql数据库中检索为blob图像时,图像被破坏

时间:2015-04-04 06:51:17

标签: php html mysql image

我每次都会破坏图像。请帮我这个我是php的新手。 imagedata是我的表中名为property的blob类型的列,我在文件print.php中的调用函数如下所示

/*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>

1 个答案:

答案 0 :(得分:0)

更改此

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

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