Home > Backend Development > PHP Tutorial > 一个关于文件上传的页面.遇到异常.求大神指导指导

一个关于文件上传的页面.遇到异常.求大神指导指导

WBOY
Release: 2016-06-13 12:48:51
Original
752 people have browsed it

一个关于文件上传的页面.遇到错误.求大神指导指导

<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><br />
<title>upload.</title><br />
<style type="text/css"><br />
<!--<br />
.STYLE2 {<br />
	font-family: "宋体";<br />
	font-weight: bold;<br />
}<br />
--><br />
</style><br />
</head><br />
<br />
<body><br />
<style type="text/css"><br />
<!--<br />
tr,td{font-size:10px}<br />
--><br />
</style><br />
<center><br />
	<h1 class="STYLE2">upload your file</h1><br />
	<p><br />
	<table border="1" cellspacing="0" cellpadding="1" bordercolordark="#ffffff" bordercolorlight="#0000ff" width="400"><br />
	<form action="up_back.php" method="post" enctype="multipart/form-data"><br />
	<tr bgcolor="#ccccff"><br />
	<td>chose your file:</td><br />
	<td><input type="file" name="upfile" size=32 /></td><br />
	</tr><br />
	<tr><br />
	<td>describe:</td><br />
	<td><input type="text" name="describe" size="42" /></td><br />
	</tr><br />
	<tr><br />
	<td>owner:</td><br />
	<td><input type="text" name="owner" size="42" /></td><br />
	</tr><br />
	<tr><br />
	<td>submit:</td><br />
	<td><center><input type="submit" value="submit" /></center></td><br />
	</tr><br />
	</form><br />
	</table><br />
	</p><br />
</center><br />
	<br />
	<br />
</body><br />
</html>
Copy after login

这个是用来前台的页面调用下面的php.
<br />
<?php<br />
if (!$_POST["upfile"]&&$_FILES["upfile"]["name"]=="")<br />
{<br />
	echo "no file<p>";<br />
	echo "click<a href=\"up_forward.html\">there</a>return!";<br />
}<br />
else <br />
{<br />
	$filepath="upload/";<br />
	$name=$filepath.$_FILES["upload"]["name"];<br />
	while (file_exists($name))<br />
	{<br />
		$temp=explode(".", $name);<br />
		$name=$temp[0]."0".".".$temp[1];<br />
	}<br />
	if(move_uploaded_file($_FILES["upfile"]["tmp_name"], $name))<br />
	{<br />
		if ($_POST["owner"])<br />
		{<br />
			$owner=$_POST["owner"];<br />
		}<br />
		else <br />
		{<br />
			$owner="NULL";<br />
		}<br />
		if ($_POST["describe"])<br />
		{<br />
			$describe=$_POST["describe"];<br />
		}<br />
		else<br />
		{<br />
			$describe="NONE";<br />
		}<br />
		$time=date("y-m-d H:m:s");<br />
		$content=$_FILES["upload"]["name"]."||".$owner."||".$describe."||".$time."\n";<br />
		file_put_contents("record.dat", $content.FILE_APPEND);<br />
		echo "name:".$_FILES["upfile"]["name"];<br />
		echo "<p>";<br />
		echo "is upload successfull.<p>";<br />
		echo "click<a href=\"up_forward.html\">there</a>return!";<br />
	}<br />
	else <br />
	{<br />
		echo "upload error!<p>";<br />
		echo "fail!<p>";<br />
		echo "click<a href=\"index.php\">there</a>check!";<br />
	}<br />
}<br />
?><br />
Copy after login

问题就在于上传之后,提示文件上传成功,但是upload文件夹里面文件名是0的倍数,而且没有文件格式..这个是怎么回事呢?


提示的错误就是下面这些..
Notice: Undefined index: upfile in D:\phpnow\htdocs\b\up_back.php on line 2

Notice: Undefined index: upload in D:\phpnow\htdocs\b\up_back.php on line 10

Notice: Undefined offset: 1 in D:\phpnow\htdocs\b\up_back.php on line 14

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template