存图片的字段设置成_bin 二进制方式存储.
读出后可直接ECHO.但在echo 前需用header送出MIME头.

解决方案 »

  1.   

    数据库字段设置成二进制形式,读取文件并写入图片文件到数据库。
    读取时取出数据,然后设置头标位图片格式的,然后echo输出刚才读取数据库的内容。
      

  2.   

    假设已经建好类似的这样一个表:
    create table pic(
    id smallint unsigned,
    pic mediumblob,
    primary key(id));
    <?php
    header("Content-Type: image/jpeg");
    $pic='F:\\program\\img\\140.jpg';//要插入的图片
    $fb= base64_encode(file_get_contents($pic));//为防止特殊字符无法插入,先base64编码 $db= mysql_pconnect("localhost","root","");
    mysql_select_db("test",$db);//pic 在test 里
    mysql_query("insert into pic values(5,'$fb');") or die(mysql_error());
    $results= mysql_query("select * from pic where id=5;");
    $row= mysql_fetch_row($results);
    echo base64_decode($row[1]);
    ?>