想取出存在数据库表中的BLOB字段的图片,在页面中显示出来.
代码如下:
<html>
<HEAD>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<HEAD>
<body>
<?php
   $host="localhost";
   $user="root";
   $password="123456";
   $database="test1";
   $table_name="teacher";
   $conn=mysql_connect($host,$user,$password);
   if(!mysql_connect($host,$user,$password))
      die("connect erroring..... ".mysql_error());  
    mysql_select_db($database,$conn);
    mysql_query("SET NAMES 'GB2312'");
    $v_find="select pic from teacher";
    $result=mysql_query($v_find,$conn) ;     while($row=mysql_fetch_object($result))
{
echo "<img src='".$row->pic."'>";
}
?>
</body>
</html>
结果:显示出来异常

解决方案 »

  1.   

    引用的图片,单独写一个文件比如<img src="picture.php?id=123">在picture.php文件,根据参数值,链接数据库,读取字段信息,echo出来
      

  2.   


    ++picture.php,只输出图片内容,其他什么都不要输出。
      

  3.   

    我的blob字段存放不是图片路径,是图片的二进制流.我按您的提示,改进如下,
    <html>
    <HEAD>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <HEAD>
    <body>
    <?php
       $host="localhost";
       $user="root";
       $password="123456";
       $database="teacher";
       $table_name="student";
       $conn=mysql_connect($host,$user,$password);
       if(!mysql_connect($host,$user,$password))
          die("connect erroring..... ".mysql_error());  
        mysql_select_db($database,$conn);
        mysql_query("SET NAMES 'GB2312'");
        $v_find="select * from student";
        $result=mysql_query($v_find,$conn) ;
         while($row=mysql_fetch_object($result))
    {
           echo  "$row->picnum";//picnum=123;
         echo "<img src=\"pic.php?picnum=$row->picnum\">"; }
    ?>
    </body>
    </html>
    代码:pic.php<?php $result=mysql_query("select * from student where picnum=$picnum").or die("can't perform query");
            $row=mysql_fetch_object($result);
             Header("Content-type:image/gif");
    echo $row->pic;   
    ?>修改后,根据没有跳到pic.php文件当,所以图片没有显示出来,只显示一个小叉号.
      

  4.   

    你数据库存放的又不是路径不能这样子弄吧,应该让它转到另一个php页面,然后根据参数获取数据库中的数据,将数据输出来,不过得记得将content-type设图片显示形式的
      

  5.   

    pic.php连接数据库了么。查看下输出了什么
      

  6.   

    修改后的pic.php
    <?php
       $host="localhost";
       $user="root";
       $password="123456";
       $database="teacher";
       $table_name="student";
       $conn=mysql_connect($host,$user,$password);
       echo "1111";
       if(!mysql_connect($host,$user,$password))
          die("connect erroring..... ".mysql_error());  
        mysql_select_db($database,$conn);
        mysql_query("SET NAMES 'GB2312'");
    $result=mysql_query("select * from student where picnum=123");
            $row=mysql_fetch_object($result);
             Header("Content-type:image/gif");
    echo $row->pic;   
    ?>
    我在执行的时候,就是没有跳转到pic.php.
    Content-type我是在程序中这样设置的 Header("Content-type:image/gif");
    还是只显示一个小叉号
    数据库如下-- 
    -- 表的结构 `student`
    -- CREATE TABLE `student` (
      `picnum` int(11) NOT NULL,
      `pic` blob NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 
    -- 导出表中的数据 `student`
    高手指点!!!万分感激.
      

  7.   

    数据库编码utf8,前台"SET NAMES 'GB2312'",后果不可预计
    echo "1111";//这一行干吗呢?
      

  8.   

    ++数据库编码utf8,程序"SET NAMES 'utf8'"你这里不能输出任何与图象数据无关的字符。
    否则浏览器无法解析你的图片
      

  9.   

    pic.php
    <?php
      $host="localhost";
      $user="root";
      $password="123456";
      $database="teacher";
      $table_name="student"; 
      $conn=mysql_connect($host,$user,$password);
      echo "1111";
      if(!mysql_connect($host,$user,$password))
      die("connect erroring..... ".mysql_error());   
      mysql_select_db($database,$conn);
    //  mysql_query("SET NAMES 'GB2312'"); //blob 类型是二进制的,不需要设置语言编码
    $result=mysql_query("select * from student where picnum=$_GET[picnum]");
      $row=mysql_fetch_object($result);
      Header("Content-type:image/gif");
    echo $row->pic;   
    ?>
    主程序
    <html>
    <HEAD>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <HEAD>
    <body>
    <?php
      $host="localhost";
      $user="root";
      $password="123456";
      $database="test1";
      $table_name="teacher"; 
      $conn=mysql_connect($host,$user,$password);
      if(!mysql_connect($host,$user,$password))
      die("connect erroring..... ".mysql_error());   
      mysql_select_db($database,$conn);
      mysql_query("SET NAMES 'GB2312'");
      $v_find="select picnum from teacher";
      $result=mysql_query($v_find,$conn) ;  while($row=mysql_fetch_object($result))
    {
    echo "<img src='pic.php?picnum=".$row->picnum."'>";
    }
    ?>
    </body>
    </html>
      

  10.   

    71.php 
    代码:<html>
    <HEAD>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <HEAD>
    <body>
    <?php
      $host="localhost";
      $user="root";
      $password="123456";
      $database="teacher";
      $table_name="student"; 
      $conn=mysql_connect($host,$user,$password);
      if(!mysql_connect($host,$user,$password))
      die("connect erroring..... ".mysql_error());   
      mysql_select_db($database,$conn);
      $v_find="select picnum from student";
      $result=mysql_query($v_find,$conn) ;  while($row=mysql_fetch_object($result))
    {
    echo "<img src='pic.php?picnum=".$row->picnum."'>";
    }
    ?>
    </body>
    </html>pic.php 代码:
    <?php
      $host="localhost";
      $user="root";
      $password="123456";
      $database="teacher";
      $table_name="student"; 
      $conn=mysql_connect($host,$user,$password);
     
      if(!mysql_connect($host,$user,$password))
      die("connect erroring..... ".mysql_error());   
      mysql_select_db($database,$conn);   $result=mysql_query("select * from student where picnum=$_GET[picnum]");
      $row=mysql_fetch_object($result);
      Header("Content-type:image/gif");
    echo $row->pic;   
    ?>页面还是显示一个小红错号,而且也没有跳至pic.php
    数据库
    CREATE TABLE `student` (
      `picnum` int(11) default NULL,
      `pic` blob NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;帮帮忙吧! 谢谢
      

  11.   

    假定你表中有 picnum = 123 的记录请直接执行
    http://localhost/pit.php?picnum=123看结果
      

  12.   

    搞定了:<?php  if($id)
    {
        @mysql_connect("localhost","root","");
        @mysql_select_db("picdb");
        
        $query = "select pic,fileType from pics where id=$id";
        $result = @mysql_query($query);
        
        $data = @mysql_result($result,0,"pic");
        $type = @mysql_result($result,0,"fileType");
        
        header("content-type:$type");
        echo $data;
    }
                              
    ?>假如本文档的名字是 picShow.php
    假如图片在表里的ID号为 1 ,则地址为
    http://localhost/picShow.php?id=1