title: C# How do I upload a file to a PHP server?
body: <p>I need to upload a file to my webserver from a C# program. The problem is, I need to also POST two strings at the same time.
  So far, I have:</p>
  
  <pre><code>            HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create("http://localhost/test.php");             
              ASCIIEncoding encoding = new ASCIIEncoding();
              string postData = "&amp;name=Test";
              postData += "&amp;email=a@a.com";
              postData += "&amp;file=file.txt";
  
              byte[] data = encoding.GetBytes(postData);
  
              HttpWReq.Method = "POST";    
              HttpWReq.ContentType = "application/x-www-form-urlencoded";   
              HttpWReq.ContentLength = data.Length;    
              Stream newStream = HttpWReq.GetRequestStream();
  
  
              newStream.Write(data, 0, data.Length);
              newStream.Close();
  </code></pre>
  
  <p>Here's the HTML and PHP:</p>
  
  <pre><code>&lt;?php
  $name = $_POST['name'];
  $email = $_POST['email'];
  $target_path = "uploads/";
  $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
  echo (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path) ? "Success!" : "Failed");
  ?&gt;
  &lt;form enctype="multipart/form-data" action="test.php" method="POST"&gt;
  Name : &lt;input type="text" name="name"&gt;&lt;br /&gt;
  Email : &lt;input type="text" name="email"&gt;&lt;br /&gt;
  File : &lt;input name="uploadedfile" type="file" /&gt;&lt;br /&gt;
  &lt;input type="submit" value="Being Upload" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I don't know where to add the file field though :\ Any help would be appreciated! </p>