各位大侠好!
请教下如何显示存入mysql表blob类型字段的图片?
我用的代码: Header( "Content-type: image/gif"); 
$sql='select imag from tablename where id=1';
$rst= $conn->execute($sql);
echo $rst['img'];存入时代码:
$fileinfo=$_FILES['attfile'];
$file_name = $fileinfo['name'];
$file_newname=$fileinfo['tmp_name'];
         $temp_a=fread(fopen($file_newname,"r"),filesize($file_newname));
         $filecontent=addslashes($temp_a);
         $sql='insert into tablename(img) values('.$filecontent.')'; 
$rst=$conn->execute($sql);
我没有分数可给,对不起啊。比较急。

解决方案 »

  1.   

    <?php
    $sql='select imag from tablename where id=1';
    $rst= $conn->execute($sql);
    $im = imagecreatefromstring($rst['img']);
    if($im != false){
    Header( "Content-type: image/gif");
    imagegif($im);
    imagedestroy($im);
    }else{
    echo 'An error occurred.';
    }
    ?>
      

  2.   

    <?php
    $sql='select imag from tablename where id=1';
    $rst= $conn->execute($sql);
    $im = imagecreatefromstring(stripslashes($rst['img']));
    if($im != false){
        Header( "Content-type: image/gif");
        imagegif($im);
        imagedestroy($im);
    }else{
        echo 'An error occurred.';
    }
    ?>
      

  3.   

    Fatal error: Cannot use object of type ADORecordSet_mysql as array in D:\apache\htdocs\stamina\showpict.php on line 14系统报错,就是imagecreatefromstring(stripslashes($rst['img']));
    怎么处理啊?
      

  4.   

    select语句错了吧,应该是select img from tablename where id=1
      

  5.   

    我的原文:
    <?php
    session_start(); 
    include_once 'conn/conn.php';

    $strId=$_GET['ID']; //记录ID
    $strTb=$_GET['TB']; //表名称
    $strGraphFn=$_GET['GRAPHNAME']; //图片字段名称
    $strIdFn=$_GET['KEYNAME']; //KEY字段名称

    $sql='select '.$strGraphFn.' from '.$strTb.' where '.$strIdFn.'='.$strId;
    $temp_graph_content= $conn->execute($sql);
    if(!($temp_graph_content==null || $temp_graph_content->RecordCount()==0))
    {
    $temp_img=imagecreatefromstring(stripslashes($temp_graph_content[$strGraphFn]));
    if ($temp_img!=false)
    {
    Header( "Content-type: image/gif"); 
    imagegif($temp_img);
    imagedestroy($temp_img);
    }else
    {
    echo 'An error occurred.';
    }
    }else
    {
    echo "";
    }
    ?>
      

  6.   

    我直接写sql语句,不用参数也一样的效果,不知道错在哪里?图片很小,是jpeg格式的。
      

  7.   

    先分两步
    1)确认你能从数据库中正确查询出数据2)将数据转为图片,JPEG格式的要用
    Header( "Content-type: image/jpeg"); 
    imagejpeg($temp_img);
      

  8.   

    我试过了,数据能够正常获得,只不过我不认识blob里面的内容(乱码),其它字段正常的。
    报错依旧,2种类型图片全试验过了。
      

  9.   

    你在插入的时候为什么要加$filecontent=addslashes($temp_a);?
    直接插入$temp_a试试
      

  10.   

    不加上addslashes处理,表里的字段值是空的,没有存进去。我查过了。