构造表单
<html> <body> <div>--------------get--------------------</div> <form action="/server.php" method="get" target="_blank"> checkbox<input type='checkbox' name='checkbox' value='checkbox'></input><br> radio<input type='radio' name='radio' value='radio'></input><br> image<input type='image' name='image' value='image'></input><br> text<input type='text' name='text' value='text'></input><br> password<input type='password' name='password' value='password'></input><br> hidden<input type='hidden' name='hidden' value='hidden'></input><br> button<input type='button' name='button' value='button'></input><br> reset<input type='reset' name='reset' value='reset'></input><br> submit<input type='submit' name='submit' value='submit'></input><br> </form> <div>--------------post--------------------</div> <form action="/server.php" method="post" target="_blank"> checkbox<input type='checkbox' name='checkbox' value='checkbox'></input><br> radio<input type='radio' name='radio' value='radio'></input><br> image<input type='image' name='image' value='image'></input><br> text<input type='text' name='text' value='text'></input><br> password<input type='password' name='password' value='password'></input><br> hidden<input type='hidden' name='hidden' value='hidden'></input><br> button<input type='button' name='button' value='button'></input><br> reset<input type='reset' name='reset' value='reset'></input><br> submit<input type='submit' name='submit' value='submit'></input><br> </form> </body> </html>
表单接收
<?php if(isset($_GET["submit"])) { echo "<div>----- get ------</div>"; foreach($_GET as $tp) { echo "$tp <br>"; } } if(isset($_POST["submit"])) { echo "<div>----- post ------</div>"; foreach($_GET as $tp) { echo "$tp <br>"; } } ?>
构造文件表单
<html> <body> <form action="/server.php" method="post" target="_blank" enctype="multipart/form-data"> <input type="file" name="picture"></input> <input type="submit" name="upload"></input> </form> </body> </html>
接收文件并保存
<?php //判断文件是否成功上传 if ($_FILES["picture"]["error"] > 0) { echo "Error: " . $_FILES["picture"]["error"] . "<br />"; } else { //输出文件信息 echo "succeed!<br>"; echo "Upload: " . $_FILES["picture"]["name"] . "<br />"; echo "Type: " . $_FILES["picture"]["type"] . "<br />"; echo "Size: " . ($_FILES["picture"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["picture"]["tmp_name"]. "<br />"; //保存文件 if (file_exists( $_FILES["picture"]["name"])) { echo $_FILES["picture"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["picture"]["tmp_name"],$_FILES["picture"]["name"]); echo "Stored in: ".$_FILES["picture"]["name"]; } } ?>