如何使用http Post将文件发送到服务器。说明?

时间:2014-01-19 12:14:53

标签: c http post

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

1 个答案:

答案 0 :(得分:3)

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"); 
}
?>