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:
HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create("http://localhost/test.php");
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "&name=Test";
postData += "&email=a@a.com";
postData += "&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();
Burada HTML ve PHP bulunuyor:
<?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");
?>
<form enctype="multipart/form-data" action="test.php" method="POST">
Name : <input type="text" name="name"><br />
Email : <input type="text" name="email"><br />
File : <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Being Upload" />
</form>
Ama dosya alanı eklemek için nerede bilmiyorum: \ Herhangi bir yardım mutluluk duyacağız!