Home >Backend Development >PHP Tutorial > 一个关于文件上传的页面.遇到异常.求大神指导指导
一个关于文件上传的页面.遇到错误.求大神指导指导
<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>
<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 />