一下是我的代码:
upf1.html
<html>
 <head>
 <title>上传图片</title>
 </head>
 <body>
 <form method="post" action="upf2.php" enctype="multipart/form-data"><center><br><br><br><br>
   <input type="hidden" value="204800" name="MAX_FILE_SIZE"/>
   File: <input type="file" name="imgfile" /><br><br>
   <input type="submit" value="OK" name="submitbtn" style="width:100px;height:23px"/></center>
 </form>
</body>
</html>upf2.php
<?php 
   //向数据库中插入图片
    $imgfile=$_FILES['imgfile'];
    $submitbtn=$_POST['submitbtn'];
    if($submitbtn=='OK' && is_array($imgfile))
    {
        $name=$imgfile['name'];  //取得图片名称
        $type=$imgfile['type']; //取得图片类型
        $size=$imgfile['size'];  //取得图片长度
        $tmpfile=$imgfile['tmp_name'];  //图片上传上来到临时文件的路径
        if($tmpfile && is_uploaded_file($tmpfile))  //判断上传文件是否为空,文件是不是上传的文件
        {
            //读取图片流
            $file=fopen($tmpfile,"rb");
            $imgdata=bin2hex(fread($file,$size));  //bin2hex()将二进制数据转换成十六进制表示
            fclose($file);
            
            $con=mysql_connect("localhost","root","199026");  //连接数据库函数
            mysql_select_db("andy");  //选择数据库
            //插入出数据库语句,图片数据前要加上0x,用于表示16进制数
            if (mysql_query("insert into images(image) values('0x.$imgdata')") )
                echo "<center>insert successful!<br><br><a href='showimage.php'>show image</a></center>";
           else
               echo "<center>insert failed!</center>";
            mysql_close();
        }
        else 
            echo "<center>Choose image!<br><br><a href='upf1.html'>back</a></center>";
    }    
    else 
        echo "<center>choose image!<br><br><a href='upf1.html'>back/a></center>";
?>showimage.php
<?php
    mysql_connect("localhost","root","199026");
    mysql_select_db("test");
    //显示最新插入的那张图片
    $result=mysql_query("select image from images ");  
    $row=mysql_fetch_object($result);
    header("Content-Type:image/pjpeg");  
    echo $row->image;
    mysql_close();
?>
显示图片是报错,错误在showimage.php里
提示错误是:
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\test\showimage.php on line 6Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\test\showimage.php:6) in C:\AppServ\www\test\showimage.php on line 7菜鸟请求更正!