如何从blob字段显示图像

时间:2011-08-04 08:52:44

标签: php mysql database blob

  

可能重复:
  How can I store and retrieve images from a MySQL database using PHP?

我已经在blob字段中完美地上传了我的图片但是我无法显示图像我使用了以下代码,但它无法正常工作:

<?php

$username = "root";
$password = "";
$host = "localhost";
$database = "bakery";

@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());

@mysql_select_db($database) or die("Can not select the database: ".mysql_error());

$id = 3 ;

if($id==3){


$query = mysql_query("SELECT img FROM pic WHERE Desc='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['image'];

header('Content-type: image/jpg');
echo $content;

}

?>

0 个答案:

没有答案