如何使用http和POST将文件发送到服务器。谁能用语法和方法向我解释?
我只想要C语言

最佳答案

upload.html

<body>
  you may upload here...
  <br><br>
  <form action="uploadhandler.php" method="post" enctype="multipart/form-data">
    <input type="file" name="file" id="file"><br><br>
    <input type="submit" name="submit" value="Submit">
  </form>
</body>


uploadhandler.php

 <?php
 if(isset($_post['submit']))
 {
    $allowedExts = array("html", "jpeg", "jpg", "png","zip");
    $extension = end($temp);
    if ((($_FILES["file"]["type"] == "application/zip")
    || ($_FILES["file"]["type"] == "application/x-zip-compressed")
    || ($_FILES["file"]["type"] == "multipart/x-zip")
    || ($_FILES["file"]["type"] == "application/x-compressed")
    || ($_FILES["file"]["type"] == "application/octet-stream"))
    && ($_FILES["file"]["size"] < 20000000))
    {
          if ($_FILES["file"]["error"] > 0)
         {
            echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
         }
         else
         {
            echo "Upload: " . $_FILES["file"]["name"] . "<br>";

         echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";


        if (file_exists("upload/" . $_FILES["file"]["name"]))
        {
           echo $_FILES["file"]["name"] . " already exists. ";
        }
        else
        {
          move_uploaded_file($_FILES["file"]["tmp_name"],"upload/". $_FILES["file"]  ["name"]);

        }
     }
     }
   else
   {
     echo "Invalid file(please upload zip file)";
     header("refresh: 1; upload.html");
    }
  }
else
{
  echo "please select a zip file";
  header("refresh: 2; upload.html");
}
?>

10-05 19:55