第3关:下拉菜单类表单内容 - 地址选择
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <select name="province"> <option value="">请选择一个省份:</option> <option value="HUNAN">湖南</option> <option value="GUANGDONG">广东</option> </select> <select name="city"> <option value="">请选择一个城市:</option> <option value="CHANGSHA">长沙</option> <option value="GUANGZHOU">广州</option> </select> <input type="submit" value="提交"> </form> <?php /********** Begin *********/ if($province = isset($_GET['province'])? $_GET['province'] : '') { if($province = isset($_GET['city'])? $_GET['city'] : '' ) { if($_GET['province'] == "湖南" && $_GET('city') == "长沙") echo '410000'; else if($_GET['province'] == "广东" && $_GET('city') == "广州") echo '510000'; else echo '选定城市不在选定省份'; } } /********** End *********/ ?> </body>
第4关:文件类表单内容 - 照片上传
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data"> <table class="reg"> <tr> <td class="title" colspan="2">文件上传</td> </tr> <tr> <th>照片文件:</th> <td><input type="file" name="file" /></td> </tr> <tr><td colspan="2" class="td-btn"> <input type="submit" value="上传文件" class="button" /> <input type="reset" value="重新选择" class="button" /> </td></tr> </table> </form> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { /********** Begin *********/ //判断文件上传是否有错误 if($_FILES['file']['error'] > 0) { die('上传文件有误!'); } //输出文件信息 else { echo '文件的名称:' . $_FILES['file']['name'] . "<br>"; echo '文件的类型:' . $_FILES['file']['type'] . "<br>"; echo '文件的大小:' . $_FILES['file']['size'] /1024 . "<br>"; echo '文件的临时路径:' . $_FILES['file']['tmp_name'] . "<br>"; } //输出文件信息 /********** End *********/ //显示上传结果 if (move_uploaded_file($_FILES['file']['tmp_name'], $_FILES['file']['name'])) { echo '上传成功!'; echo "<img src='" . $_FILES['file']['name'] . "'><br>"; } else { die("上传错误!"); } } ?> </body>