<?php
include"1.php";
$info=nl2br($info);
if($pic!="none")
{
$fp=fopen($pic,"r");
$data=addslashes(fread($fp,filesize($pic)));
}
$filesize=filesize($pic);
$filetype=filetype($pic);
$filename=basename($pic);
$date=date("Y-m-d H:i:s");
$sql="insert into photo(info,name,time,pic,filename,filesize,filetype) values('$info','$name','$date','$data','$filename','$filesize','$filetype')";
if(mysql_query($sql))
{
header("Location:photo.php");
}
?>
老师显示说第七行不是有效的值,问题出在哪里呢?
include"1.php";
$info=nl2br($info);
if($pic!="none")
{
$fp=fopen($pic,"r");
$data=addslashes(fread($fp,filesize($pic)));
}
$filesize=filesize($pic);
$filetype=filetype($pic);
$filename=basename($pic);
$date=date("Y-m-d H:i:s");
$sql="insert into photo(info,name,time,pic,filename,filesize,filetype) values('$info','$name','$date','$data','$filename','$filesize','$filetype')";
if(mysql_query($sql))
{
header("Location:photo.php");
}
?>
老师显示说第七行不是有效的值,问题出在哪里呢?
后面验证下$fp的有效性if (!$fp) {
// 这里报错
}
这个是我前台文件
<!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=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function check()
{
if(window.document.pic.name.value=="")
{
alert("请输入图片的名称");
document.pic.name.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<table width="520" border="0" align="center">
<?php
?>
<form action="put_pic.php" method="post" name="pic" enctype="multipart/form-data" onsubmit="return check();">
<tr>
<td width="520" bgcolor="#9FCF6F" colspan="2">上传图片</td>
</tr>
<tr>
<td width="160" bgcolor="#C2E0A5" align="right">图片名称:</td>
<td width="360"><input type="text" name="name" size="35"></td>
</tr>
<tr>
<td width="160" bgcolor="#C2E0A5" align="right">图片说明:</td>
<td width="360"><textarea name="info" cols="34" rows="8"></textarea></td>
</tr>
<tr>
<td width="160" bgcolor="#C2E0A5" align="right">图片文件:</td>
<td width="360"><input type="file" name="tp" size="25"></td>
</tr>
<tr>
<td width="520" bgcolor="#9FCF6F" colspan="2" align="center"><input type="submit" value="提交" name="bt1"><input type="reset" name="reset" value="重写"></td>
</tr>
</table></form>
</body>
</html>
麻烦各位了