实现数据库存储图片问题
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>
<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><?phpinclude("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;?>">