index.php文件<?php 
include("conn.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>插入MYSQL图片</title>
</head><body>
<table cellpadding="0" cellspacing="0" align="center" bgcolor="#00FFFF" border="1">
 <form action="index_ok.php" method="post" enctype="multipart/form-data">
  <tr>
   <td align="center"><input type="file" name="picture" size="25"></td>
   <td align="center"><input type="submit" name="submit" value="上传"></td>
  </tr>
 </form>
</table>
<table align="center" cellpadding="0" cellspacing="0" border="2">
  <tr><td width="150"><font color="#0000FF" size="+3">显示图片</font></td></tr>
<?php 
// 调用方法: getdata.php3?id= 
  //include( "class.Mysql.php" );
   $id=intval($_GET['id']);
   $result=@mysql_query("select * from tb_up_files where id=2",$conn);
   $fet=@mysql_fetch_array($result,$conn);
 //header( "Content-type: image/jpg");
?>
    <tr><td width="150" align="center"><?php //echo "<img src=\"$fet[path]\">";
echo $fet['path'];?></td></tr></table>
</body>
</html>

解决方案 »

  1.   

    index_ok.php文件<?php 
    //header("Content-Type:text/html ; charset=utf-8");
    include("conn.php");
    if($_POST['submit']!=""){
      $file= $_FILES['picture'];
    $data=addslashes(fread(fopen($file['tmp_name'],r),filesize($file['tmp_name'])));
    $sql=@mysql_query("insert into tb_up_files(path) values('$data')",$conn);
        $id= mysql_insert_id(); 
            print " This file has the following Database ID: $id";    
            mysql_close(); 
    echo "图片上传成功,请稍后...";
    echo "<meta http-equiv=\"refresh\" content=\"3;url=index.php\">";

    }
    ?>
      

  2.   

    修正:$result=@mysql_query("select * from tb_up_files where id=$id",$conn);
      

  3.   

    本帖最后由 xuzuning 于 2012-10-07 11:46:01 编辑
      

  4.   

    设读取图片的php程序为 pict.php
    include("conn.php");
    $id=intval($_GET['id']);
    $result=@mysql_query("select * from tb_up_files where id=$id");
    $fet=@mysql_fetch_array($result,$conn);
    echo $fet['path'];那么显示时为
    <img src='pict.php?id=2'>
      

  5.   

    LS 正解
    当心php文件不能输出别的东西,
    包括空格之类的
      

  6.   

    数据库存路径..开一个文件夹存图片<form action="pic.php" method="post" enctype="multipart/form-data" name="form1">
      <label for="file"></label>
      <input type="file" name="file" id="file">
      <input type="submit" name="submit" id="submit" value="提交">
    </form>
    <?php
    include("conn.php");
    $f=$HTTP_POST_FILES['file'];
    $dest_dir='./abc';//设定上传目录
    $extend =explode("." , $f['name']);
    $kuozhan=end($extend);//获取文件扩展名 
    $dest=$dest_dir.'/'.date("ymdhms").'.'.$kuozhan;//文件名为当前时间
    $r=move_uploaded_file($f['tmp_name'],$dest);
    chmod($dest, 0755);//设定上传的文件的属性
    if($r)
    {    $sql="insert into path(patn) values('$dest')";
    $queryt=mysql_query($sql);
     echo "<script>alert('上传成功,目录为".$dest."');</script>";
    }
    else
    {
    echo "<script>alert('上传失败');</script>";
    }

    $sqlpic="select * from path order by id desc limit 1";//取出最新的一条记录
        $query2=mysql_query($sqlpic);
    $result=mysql_fetch_array($query2);
    $picpath=$result['patn'];//最新的图片路径
    ?>
    <img src="<?php echo $picpath;?>">
      

  7.   

    <img src="pict.php?id=<?=$_GET['id']?>">输出不了 但<img src="pict.php?id=2">可以