1

First

I have a PHP file that gets data and file from a HTML form and uploads a file to a specific directory by the $_POST and $_FILES methods.

Second

I have Windows aplication (C#). The user can drag and drop any file to a listview. I send the user's data to a PHP file by the POST method and it (the PHP file) upadtes the database. My problem is I won't to send file in listview drag and dropped by the user to the PHP file as it could get the file by the $_FILES method and access it.

Community
  • 1
  • 1
ozman
  • 256
  • 1
  • 4
  • 18

2 Answers2

2

If you want to POST a single file from C# to your PHP script you could use the UploadFile method:

using (var client = new WebClient())
{
    client.UploadFile("http://example.com/script.php", "POST", @"C:\path\test.txt");
}

If along with the file you want to send some other data and/or multiple files you will need to forge a multipart/form-data request manually. Here's a post explaining how to achieve this.

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Mr Dimitrov I do what you said As Below using (var client = new WebClient()) { client.UploadFile("http://K45/j/_dokuman/Dokuman/Islem22.php", "POST", @"C:\test.txt"); } – ozman Mar 06 '10 at 09:10
  • MY "Islem22.php" is like this.But it didnt upload the file to specified directory $filename = $_FILES['DosyaAdi']['name']; $temp = explode('.',$filename); $temp = array_reverse($temp); $Uzanti = $temp[0]; if(move_uploaded_file($_FILES['DosyaAdi']['tmp_name'], "C://www/wamp/j")) { alert( basename( $_FILES['DosyaAdi']['name'])." dosyası başarıyla yüklendi"); } – ozman Mar 06 '10 at 09:12
  • 1
    `UploadFile` uses `file` as name. Try with `$_FILES['file']['name']`. If you want more control over this you may take a look at this article http://www.codeproject.com/KB/cs/uploadfileex.aspx?display=Print – Darin Dimitrov Mar 06 '10 at 09:46
  • Thanx Dimitrov.I use $_FILES['file']['name'] file instead of DosyaAdi then everything become Right .Thanks alot – ozman Mar 06 '10 at 09:56
-3

Learn the HTTP protocol and pray for the site owner not banning the user's IP address for the terms-of-use violation.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345