大家好:
请帮我看看下面的问题:
conn.php
<?php
$link=mysql_connect("localhost","root","roy513484978");
mysql_select_db('db_imageupload',$link);
mysql_query("set names gb2312");
?>#############index.php######
<?php include("conn/conn.php");?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片上传</title>
<style type="text/css">
<!--
td {
font-size:12px;
}
-->
</style>
</head>
<body>
<table width="350" height="150" border="0" align="center" cellpadding="0" cellspacing="0" background="images/bg.gif">
<form name="form1" method="post" action="tptj_ok.php" enctype="multipart/form-data">
<tr>
<td height="46" colspan="2" align="right"> <br></td>
</tr>
<tr>
<td width="30" height="27" align="center"> </td>
<td width="320" align="left">图片名称:
<input name="tpmc" type="text" id="tpmc" size="27"></td>
</tr>
<tr>
<td height="33" align="center"> </td>
<td align="left">上传路径:
<input name="file" type="file" size="23" maxlength="60" ></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="sc" type="submit" id="sc" value="上传">
<input name="qx" type="reset" id="qx" value="取消"></td></tr>
<tr>
<td height="13" colspan="2" align="right"> </td>
</tr>
</form>
</table>
<p> </p>
<table width="500" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#e5e5e5">
<tr align="left" colspan="2" >
<td height="25" colspan="3" background="images/top.gif"> </td>
</tr>
<?php
if($_GET[page]=="" || is_numeric($_GET[page]==false))
{
$page=1;
}
else
{
$page=$_GET[page];
}
$page_size=4; //每页显示4张图片
$query="select count(*) as total from tb_tpsc order by scsj desc";
$result=mysql_query($query); //查询总的记录条数
$message_count=mysql_result($result,0,"total"); //为变量赋值
if($message_count==0)
{
echo "暂无图片!";
}
else
{
if($message_count<$page_size)
{
$page_count=1;
}
else
{
if($message_count%$page_size==0)
{
$page_count=$message_count/$page_size;
}
else
{
$page_count=ceil($message_count/$page_size);
}
}
$offset=($page-1)*$page_size;
$query="select * from tb_tpsc where scsj order by id desc limit $offset, $page_size";
$result=mysql_query($query);
?>
<table width="496" border="1" align="center" cellpadding="3" cellspacing="1" bordercolor="#D6D7D6">
<tr>
<?php
$i=1;
while($info=mysql_fetch_array($result))
{
if($i%2==0)
{
?>
<td width="500" height="180"><table width="237" height="185" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="160"colspan="2"><div align="center"><img src="image.php?recid=<?php echo $info[id];?>" width="225" height="160"></div></td>
</tr>
<tr>
<td width="105" height="25" align="left"> 图片名称:<?php echo $info[tpmc];?></td>
<td width="132">上传时间:<?php echo $info[scsj];?></td>
</tr>
</table></td>
</tr>
<?php
}
else
{
?>
<td width="500" height="180"><table width="236" height="185" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="160" colspan="2"><div align="center"><img src="image.php?recid=<?php echo $info[id];?>" width="225" height="160"></div></td>
</tr>
<tr>
<td width="106" height="25"> 图片名称:<?php echo $info[tpmc];?></td>
<td width="130">上传时间: <?php echo $info[scsj];?></td>
</tr>
</table></td>
<?php
}
$i++;
echo"到这里了!";
}
?>
</tr>
</table>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="52%"> 页次:<?php echo $page;?>/<?php echo $page_count;?>页 记录:<?php echo $message_count;?> 条 </td>
<td align="right" class="hongse01">
<?php
if($page!=1)
{
echo "<a href=index.php?page=1>首页</a> ";
echo "<a href=index.php?page=".($page-1).">上一页</a> ";
}
if($page<$page_count)
{
echo "<a href=index.php?page=".($page+1).">下一页</a> ";
echo "<a href=index.php?page=".$page_count.">尾页</a>";
}
}
?>
</td>
</tr>
</table>
</body>
</html>#############tptj_ok.php##########<?php
include("conn/conn.php");
if($sc<>" "){
$tpmc = $_POST['tpmc'];
$file = $_POST['file'];
$tpmc=htmlspecialchars($tpmc); //将图片名称中的特殊字符转换成HTML格式
$tpmc=str_replace("\n","<br>",$tpmc); //将图片名称中的回车符以自动换行符取代
$tpmc=str_replace(""," ",$tpmc); //将图片名称中的空格以" "取代
$scsj=date("y;m;d"); //设置图片的上传时间
$fp=fopen($file,"r"); //以只读方式打开文件
$file=addslashes(fread($fp,filesize($file))); //将文件中的引号部分加上反斜线
$query="insert into tb_tpsc (tpmc,file,scsj) values ('$tpmc','$file','$scsj')"; //创建插入图片数据的sql语句
$result=mysql_query($query);
echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">图片上传成功,请稍等...";
}
?>###############image.php##############<?php
include "conn/conn.php";
$query="select * from tb_tpsc where id=".$recid;
$result=mysql_query($query);
if(!$result)
die("error: mysql query");
$num=mysql_num_rows($result);
if($num<1) die("error: no this recorder");
$data = mysql_result($result,0,"file");
echo $data;
?> 就是读不出来图片,麻烦大家帮忙看看
我是想把图片以二进制方式存入数据库,然后遍历出来
请帮我看看下面的问题:
conn.php
<?php
$link=mysql_connect("localhost","root","roy513484978");
mysql_select_db('db_imageupload',$link);
mysql_query("set names gb2312");
?>#############index.php######
<?php include("conn/conn.php");?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片上传</title>
<style type="text/css">
<!--
td {
font-size:12px;
}
-->
</style>
</head>
<body>
<table width="350" height="150" border="0" align="center" cellpadding="0" cellspacing="0" background="images/bg.gif">
<form name="form1" method="post" action="tptj_ok.php" enctype="multipart/form-data">
<tr>
<td height="46" colspan="2" align="right"> <br></td>
</tr>
<tr>
<td width="30" height="27" align="center"> </td>
<td width="320" align="left">图片名称:
<input name="tpmc" type="text" id="tpmc" size="27"></td>
</tr>
<tr>
<td height="33" align="center"> </td>
<td align="left">上传路径:
<input name="file" type="file" size="23" maxlength="60" ></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="sc" type="submit" id="sc" value="上传">
<input name="qx" type="reset" id="qx" value="取消"></td></tr>
<tr>
<td height="13" colspan="2" align="right"> </td>
</tr>
</form>
</table>
<p> </p>
<table width="500" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#e5e5e5">
<tr align="left" colspan="2" >
<td height="25" colspan="3" background="images/top.gif"> </td>
</tr>
<?php
if($_GET[page]=="" || is_numeric($_GET[page]==false))
{
$page=1;
}
else
{
$page=$_GET[page];
}
$page_size=4; //每页显示4张图片
$query="select count(*) as total from tb_tpsc order by scsj desc";
$result=mysql_query($query); //查询总的记录条数
$message_count=mysql_result($result,0,"total"); //为变量赋值
if($message_count==0)
{
echo "暂无图片!";
}
else
{
if($message_count<$page_size)
{
$page_count=1;
}
else
{
if($message_count%$page_size==0)
{
$page_count=$message_count/$page_size;
}
else
{
$page_count=ceil($message_count/$page_size);
}
}
$offset=($page-1)*$page_size;
$query="select * from tb_tpsc where scsj order by id desc limit $offset, $page_size";
$result=mysql_query($query);
?>
<table width="496" border="1" align="center" cellpadding="3" cellspacing="1" bordercolor="#D6D7D6">
<tr>
<?php
$i=1;
while($info=mysql_fetch_array($result))
{
if($i%2==0)
{
?>
<td width="500" height="180"><table width="237" height="185" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="160"colspan="2"><div align="center"><img src="image.php?recid=<?php echo $info[id];?>" width="225" height="160"></div></td>
</tr>
<tr>
<td width="105" height="25" align="left"> 图片名称:<?php echo $info[tpmc];?></td>
<td width="132">上传时间:<?php echo $info[scsj];?></td>
</tr>
</table></td>
</tr>
<?php
}
else
{
?>
<td width="500" height="180"><table width="236" height="185" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="160" colspan="2"><div align="center"><img src="image.php?recid=<?php echo $info[id];?>" width="225" height="160"></div></td>
</tr>
<tr>
<td width="106" height="25"> 图片名称:<?php echo $info[tpmc];?></td>
<td width="130">上传时间: <?php echo $info[scsj];?></td>
</tr>
</table></td>
<?php
}
$i++;
echo"到这里了!";
}
?>
</tr>
</table>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="52%"> 页次:<?php echo $page;?>/<?php echo $page_count;?>页 记录:<?php echo $message_count;?> 条 </td>
<td align="right" class="hongse01">
<?php
if($page!=1)
{
echo "<a href=index.php?page=1>首页</a> ";
echo "<a href=index.php?page=".($page-1).">上一页</a> ";
}
if($page<$page_count)
{
echo "<a href=index.php?page=".($page+1).">下一页</a> ";
echo "<a href=index.php?page=".$page_count.">尾页</a>";
}
}
?>
</td>
</tr>
</table>
</body>
</html>#############tptj_ok.php##########<?php
include("conn/conn.php");
if($sc<>" "){
$tpmc = $_POST['tpmc'];
$file = $_POST['file'];
$tpmc=htmlspecialchars($tpmc); //将图片名称中的特殊字符转换成HTML格式
$tpmc=str_replace("\n","<br>",$tpmc); //将图片名称中的回车符以自动换行符取代
$tpmc=str_replace(""," ",$tpmc); //将图片名称中的空格以" "取代
$scsj=date("y;m;d"); //设置图片的上传时间
$fp=fopen($file,"r"); //以只读方式打开文件
$file=addslashes(fread($fp,filesize($file))); //将文件中的引号部分加上反斜线
$query="insert into tb_tpsc (tpmc,file,scsj) values ('$tpmc','$file','$scsj')"; //创建插入图片数据的sql语句
$result=mysql_query($query);
echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">图片上传成功,请稍等...";
}
?>###############image.php##############<?php
include "conn/conn.php";
$query="select * from tb_tpsc where id=".$recid;
$result=mysql_query($query);
if(!$result)
die("error: mysql query");
$num=mysql_num_rows($result);
if($num<1) die("error: no this recorder");
$data = mysql_result($result,0,"file");
echo $data;
?> 就是读不出来图片,麻烦大家帮忙看看
我是想把图片以二进制方式存入数据库,然后遍历出来
$strFile = base64_encode(file_get_contents($file));
2 echo base64_decode($data); 显示前要用header指定图片的类型. 比如说header("Content-type: image/gif");
if ($im !== false) {
header('Content-Type: image/png'); // or header('Content-Type: image/jpeg');
imagepng($im); // or imagejpeg($im);
imagedestroy($im);
}
// 具体请参照PHP手册
指定类型 header('Content-Type: image/png'); 看看手册有相应函数