首页上一页 1 下一页尾页 1 条记录 1/1页
关于图片上传管理,求助
发表在PHP图书答疑
2010-04-30
是否精华
是
否
版块置顶:
是
否
关于php范例开发宝典的 12章 文件上传,整章的代码都有问题,而且问题都一样。在此以03一例提问,关于本章的所有例子在添加文件的时候都不能用2进制形式写入数据库,sql执行之后,相关字段都是0kb,而且图片展示页面都是无法正常读取数据库中的2进展码,就连实例的数据库原有的图片文件也不能读取。主要就是这两个问题,只有3个文件。希望大大能帮忙解决。
------------
运行之后错误的代码:
Notice: Undefined variable: image in D:\apmxe\htdocs\mrr\309\index_ok.php on line 5
Warning: fopen() [function.fopen]: Filename cannot be empty in D:\apmxe\htdocs\mrr\309\index_ok.php on line 5
Notice: Undefined variable: image in D:\apmxe\htdocs\mrr\309\index_ok.php on line 6
Warning: fread(): supplied argument is not a valid stream resource in D:\apmxe\htdocs\mrr\309\index_ok.php on line 6
Notice: Undefined index: image in D:\apmxe\htdocs\mrr\309\index_ok.php on line 7
请输入图片...
------------
index.php
<form action="index_ok.php" method="post" enctype="multipart/form-data" name="form1" >
<tr>
<td width="110" height="65" align="right"> </td>
<td width="184" align="center"> </td>
<td width="61"> </td>
</tr>
<tr>
<td height="25" align="right"> </td>
<td valign="middle"> </td>
<td valign="middle"> </td>
</tr>
<tr>
<td height="35"> </td>
<td align="left" valign="middle"><input name="image" type="file" id="image" size="15"></td>
<td> </td>
</tr>
<tr>
<td height="44"> </td>
<td align="center" valign="middle"><input type="submit" name="submit" value="提交"></td>
<td> </td>
</tr>
<tr>
<td height="52"> </td>
<td align="center" valign="top"> </td>
<td> </td>
</tr>
</form>
----------
index_ok.php
<?php include("conn/conn.php");?>
<?php if(@$_POST['submit']){
$names="images";
$data=date("y;m;d");
$fp=fopen($image,"rb");
$image=addslashes(fread($fp,filesize($image)));
if($_POST['image']){
$query="insert into tb_image1 (image_name,image,data)values('$names','$image','$data')";
$result=mysql_query($query,$id);
echo "<meta http-equiv=\"refresh\" content=\"10;url=index.php\">请稍等...";
}else{
echo "<meta http-equiv=\"refresh\" content=\"10;url=index.php\">请输入图片..."; } }
?>
------------
image_1.php
<?php include("conn/conn.php");
$query="select * from tb_image1 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,"image");
mysql_close($id);
echo $data;
?>
----------
--
-- 表的结构 `tb_image1`
--
CREATE TABLE IF NOT EXISTS `tb_image1` (
`id` int(11) NOT NULL auto_increment,
`image_name` varchar(30) NOT NULL,
`image` blob NOT NULL,
`data` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312 AUTO_INCREMENT=7 ;
------------
运行之后错误的代码:
Notice: Undefined variable: image in D:\apmxe\htdocs\mrr\309\index_ok.php on line 5
Warning: fopen() [function.fopen]: Filename cannot be empty in D:\apmxe\htdocs\mrr\309\index_ok.php on line 5
Notice: Undefined variable: image in D:\apmxe\htdocs\mrr\309\index_ok.php on line 6
Warning: fread(): supplied argument is not a valid stream resource in D:\apmxe\htdocs\mrr\309\index_ok.php on line 6
Notice: Undefined index: image in D:\apmxe\htdocs\mrr\309\index_ok.php on line 7
请输入图片...
------------
index.php
<form action="index_ok.php" method="post" enctype="multipart/form-data" name="form1" >
<tr>
<td width="110" height="65" align="right"> </td>
<td width="184" align="center"> </td>
<td width="61"> </td>
</tr>
<tr>
<td height="25" align="right"> </td>
<td valign="middle"> </td>
<td valign="middle"> </td>
</tr>
<tr>
<td height="35"> </td>
<td align="left" valign="middle"><input name="image" type="file" id="image" size="15"></td>
<td> </td>
</tr>
<tr>
<td height="44"> </td>
<td align="center" valign="middle"><input type="submit" name="submit" value="提交"></td>
<td> </td>
</tr>
<tr>
<td height="52"> </td>
<td align="center" valign="top"> </td>
<td> </td>
</tr>
</form>
----------
index_ok.php
<?php include("conn/conn.php");?>
<?php if(@$_POST['submit']){
$names="images";
$data=date("y;m;d");
$fp=fopen($image,"rb");
$image=addslashes(fread($fp,filesize($image)));
if($_POST['image']){
$query="insert into tb_image1 (image_name,image,data)values('$names','$image','$data')";
$result=mysql_query($query,$id);
echo "<meta http-equiv=\"refresh\" content=\"10;url=index.php\">请稍等...";
}else{
echo "<meta http-equiv=\"refresh\" content=\"10;url=index.php\">请输入图片..."; } }
?>
------------
image_1.php
<?php include("conn/conn.php");
$query="select * from tb_image1 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,"image");
mysql_close($id);
echo $data;
?>
----------
--
-- 表的结构 `tb_image1`
--
CREATE TABLE IF NOT EXISTS `tb_image1` (
`id` int(11) NOT NULL auto_increment,
`image_name` varchar(30) NOT NULL,
`image` blob NOT NULL,
`data` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312 AUTO_INCREMENT=7 ;