zoukankan      html  css  js  c++  java
  • 表单提交与接收 文件提交与接收

    构造表单

    <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"];
        }
    }
    ?>
  • 相关阅读:
    bzoj1951 [Sdoi2010]古代猪文
    bzoj2693 jzptab
    数学一本通第三章总结
    poj1019 Number Sequence
    SGU179 Brackets light
    字母组合2
    字母组合
    Java基础知识强化之集合框架笔记09:Collection集合迭代器使用的问题探讨
    Java基础知识强化之集合框架笔记08:Collection集合自定义对象并遍历案例(使用迭代器)
    Java基础知识强化之集合框架笔记07:Collection集合的遍历之迭代器遍历
  • 原文地址:https://www.cnblogs.com/qiusuo/p/5128350.html
Copyright © 2011-2022 走看看