100分,上传图片,显示图片的进来。
看了精华帖的帖子也没办法解决,上传图片后,却什么也没显示。奇怪!
但数据库,数据库里都记录了,就是在显示页面(photo.php)时候是空白。为什么无法显示图片了?
put_pic.php页面
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>put_pic.</title>
</head>
<body>
<?php
//连接数据库
$Connid=@mysql_Connect("localhost","weizhou45c5011","dellhappy2003");
//将图片文件说明文字中的换行符转换为br符号
$info=nl2br($info);
//打开图片文件,将图片文件中的数据用函数addslashes处理,然后传递给变量$data,变量$data中所保存的数据就是图片文件的数据了。
if($pic !="none")
{
$fp=fopen($_FILES['pic']['tmp_name'],"r");
$data=addslashes(fread($fp,$_FILES['pic']['size']));
}
//获取图片文件的大小
$filesize=$_FILES['pic']['size'];
//获取图片文件的类型
$filetype=$_FILES['pic']['type'];
//获取图片文件的文件名
$filename=$_FILES['pic']['name'];
//将服务器的时间传递给变量$date
$date=date("Y-m-d H:i:s");
$query="insert into photo
(info,name,time,pic,filename,filesize,filetype)
values
('$_POST[info]','$_POST[name]','$date','$data',
'$filename','$filesize','$filetype')";
if (mysql_db_query("photo",$query))
{
header("Location: photo.php");
}
?>
</body>
</html>
show.php页面
<?php
//连接服务器数据库
Connid=@mysql_connect("localhost","weizhou45c5011","dellhappy2003");
//************************
//在数据表$table中读取字段id的值
$sql="select pic from $table where id=$id";
$result=mysql_db_query("photo",$sql);
//读取图片文件内容
$image=mysql_result($result,0,"pic");
//显示图片文件
echo $image;
?>
photo.php页面
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>photo</title>
<link href="51new.css" rel="stylesheet" type="text/css">
</head>
<body>
<table border="0" cellpadding="2" width="520" class="NT9" height="288">
<tr>
<td width="520" bgcolor="#9FCF6F" colspan="3" align="center" height="16">
相片集</td></tr>
<?php
//初始化分页变量$offset
if($offset=="")
{
$offset=0;
}
//连接服务器数据库
$Connid=@mysql_connect("localhost","weizhou45c5011","dellhappy2003");
//在数据表photo中按字段id逆序
//查询指定位置的6条记录的图片名称以及图片标识号等数据。
$sql="select id,name from photo order by id desc limit $offset,6";
$result=mysql_db_query("photo",$sql);
$num=mysql_num_rows($result);
if ($num !=0)
{
//初始化表格换行变量$i
$i=0
//以while循环的方式依次显示所查询到的图片文件的图片和名称
while($r=mysql_fetch_array($result))
{
$id=$r["id"];
$ftitle=$r["name"];
if($i==0 or $i==3)
{
echo "<tr>";
}
echo"<td width=165 bgcolor=#C2E0A5 class=NT9 align=center height=126>";
//使用程序show.php来显示保存在数据表photo中的图片文件。
echo"<a href=photo_info.php?id=$fid>";
echo"<img border=0 src=";
echo"show.php?table=photo&id=$fid";
echo" height=60 ></a>";
//显示图片文件的名称
echo"<a href=photo_info.php?id=$fid>";
echo"<p>$ftitle</p></a></td>";
if($i==2 or $i==5)
{
echo "<tr>";
}
$i++;
}
}
?>
</table>
</body>
</html>
photo_info.php页面
<?php
$Connid=@mysql_connect("localhost","weizhou45c5011","dellhappy2003");
$query="select*from photo where id= '$id'";
$result=mysql_db_query("photo",$query);
$fname=mysql_result($result,0,"name");
$ftime=mysql_result($result,0,"time");
$finfo=mysql_result($result,0,"info");
$fid=mysql_result($result,0,"id");
$filetype=mysql_result($result,0,"filetype");
$filetype=mysql_result($result,0,"filesize");
$filename=mysql_result($result,0,"filename");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>
<?php
echo $_FILES[ftitle];
?>
</title>
<link href="51new.css" rel="stylesheet" type="text/css">
</head>
<body></title>
<table border="0" cellpadding="2" width="520" class="NT9">
<tr>
<td width="520" bgcolor="#9FCF6F" colspan="2" align="center"> 相片集 </td>
</tr>
<tr>
<td width="60" bgcolor="#C2E0A5" class="NT9" align="center">标题</td>
<td width="460" class="MT9" bgcolor="#C2E0A5">
<?php
echo $_FILES[ftitle];
?>
</td>
</tr>
<tr>
<td width="60" bgcolor="#C2E0A5" class="NT9" align="center">文件名</td>
<td width="460" class="MT9" bgcolor="#C2E0A5">
<?php
echo $_FILES[filename];
?>
</td>
</tr>
<tr>
<td width="60" bgcolor="#C2E0A5" class="NT9" align="center">文件类型</td>
<td width="460" class="MT9" bgcolor="#C2E0A5">
<?php
echo $_FILES[filetype];
?>
</td>
</tr></tr>
<tr>
<td width="60" bgcolor="#C2E0A5" class="NT9" align="center">上传时间</td>
<td width="460" class="MT9" bgcolor="#C2E0A5">
<?php
echo $_FILES[ftime];
?>
</td>
</tr></tr>
<tr>
<td width="60" bgcolor="#C2E0A5" class="NT9" align="center">图片</td>
<td width="460" class="MT9" bgcolor="#C2E0A5">
<?php
//使用SHOW.PHP程序来显示保存在数据库中的图片文件。
?>
<img src="show.php?table=photo&id=<?php echo $_FILES[id]; ?>"
width=300 align="center"></a> </td>
</tr>
<tr>
<td width="460" class="NT9" bgcolor="#c2e0a5">
<?php
echo $_FILES[finfo];
?>
</td>
</tr>
</table>
</body>
</html>
如果不会看出问题,给个代码研究(要数据库),一定给分。