按道理来说,图片是应该按照路径存在数据表中的,由于工作需要,需要将图片以二进制流的情况存入数据库,现在将数据表table中一个字段picture,类型改为 longblob,已经能成功将二进制流写入该字段,可是我需要将该图片在内容页中显示出来,以下代码是我在图片的位置嵌入的php代码,图片死活不显示,大家帮忙看看怎么回事?(存入数据库的图片也是jpg格式的)
                                                      
<?php                                                       
include("config.php");
mysql_connect($host,$username,$password) or die("Unable to connect to SQL server"); 
@mysql_select_db($db) or die("Unable to select database"); 
$sql=mysql_query("SELECT * FROM table where id=5") or die("Can't Perform Query"); 
Header( "Content-type: image/jpg");
$r=mysql_fetch_object($sql);
echo $r->picture;
?>                                                       
其中config.php包含了变量的定义
                                                       
                                                        

解决方案 »

  1.   

    <?php                                                      
    include("config.php"); 
    mysql_connect($host,$username,$password) or die("Unable to connect to SQL server"); 
    @mysql_select_db($db) or die("Unable to select database"); 
    $sql=mysql_query("SELECT * FROM table where id=5") or die("Can't Perform Query"); 
    Header( "Content-type: image/jpg"); 
    $r=mysql_fetch_object($sql); 
    echo imagecreatefromstring($r->picture);
    ?>
      

  2.   

    莫非这个函数就ok
    imagecreatefromstring();
      

  3.   

    改为echo imagecreatefromstring($r->picture);还是不行啊!
      

  4.   

    Header( "Content-type: image/jpeg"); 
      

  5.   

    表image里有4个字段id、picture1、picture2、picture3。为什么只有echo $row->picture1;能显示出图片。如果把第一个echo注释掉,第二个能正常显示,第三个echo不显示。把前两个注释掉,第三个echo就能正常显示了,为啥呢 ?<?php
    mysql_connect("localhost","root","123456");
    mysql_select_db("test");$query=mysql_query("select * from image");
    while($row=mysql_fetch_object($query)){
    Header( "Content-type: image/gif");
    echo $row->picture1;
    echo $row->picture2;
    echo $row->picture3;
    }
    ?>新手求知!!!
      

  6.   

    我的终于图片显示成功了,哈哈!
    这位兄弟,看看这篇文章,就能解决每次只显示一张照片的问题
    多谢各位朋友的帮助,正是大家集思广益,我才受到启发,同时也学会了不少新知识,比如imagecreatefromstring等等
      

  7.   

    我的终于图片显示成功了,哈哈!
    这位兄弟,看看这篇文章,就能解决每次只显示一张照片的问题
    多谢各位朋友的帮助,正是大家集思广益,我才受到启发,同时也学会了不少新知识,比如imagecreatefromstring等等