In my recent project I had to upload a file to a php server from a client application developed in C#. I found this method and I thought to share this with you.

First you have to use the System.net namespace. Then you have to create a webclient object. Using webclient object you can upload your file to a php file in the server.

using System.Net;
WebClient cl = new WebClient();
try{

    cl.UploadFile("http://" + ip + "/test.php", file);
}
catch(Exception e)
{
    MessageBox.Show("Upload failed");
}

Now you can access the file from the php file. In the below example I create a folder in the server machine and move the file into the folder.

<?php
//check whether the folder the exists
if(!(file_exists('C:/Users/dhanu-sdu/Desktop/test')))
{
  //create the folder
  mkdir('C:/Users/dhanu-sdu/Desktop/test');
  //give permission to the folder
  chmod('C:/Users/dhanu-sdu/Desktop/test', 0777);
}

//check whether the file exists
if (file_exists('C:/Users/dhanu-sdu/Desktop/test/'. $_FILES["file"]["name"]))
{
  echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
  //move the file into the new folder
  move_uploaded_file($_FILES["file"]["tmp_name"],'C:/Users/dhanu-sdu/Desktop/test/'. $_FILES["file"]["name"]);

}

?>

Also You can download data from a php server and display it in C# web browser by using the following code.

WebClient cl = new WebClient();
try{
    byte[] response = cl.DownloadData("http://" + ip +"/test.php");
    webBrowser1.DocumentText = System.Text.ASCIIEncoding.ASCII.GetString(response);
}
catch(Exception e)
{
    MessageBox.Show("Download failed");
}