Hello dear users!

It is required to upload a file (file.bin) to the POST script with a C # request. I don’t even have to talk about file uploading on FTP; I will be glad to any help.

PHP script itself:

<?php $file1 = $_FILES['data']['tmp_name']; $name = basename($_FILES['data']['name']); $dir1 = mkdir('up/'); $dir='up/'; $id=$_POST['data2']; if (!file_exists($file1)) { echo "ERROR"; } else { move_uploaded_file($file1, $dir.$name); echo "OK <br>"; echo $id; } ?> 

Thanks in advance!

Closed due to the fact that off-topic participants are Vladimir Martyanov , Ella Svetlaya , null , ixSci , Abyx 24 May '15 at 12:25 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "Questions asking for help with debugging (" why does this code not work? ") Should include the desired behavior , a specific problem or error, and the minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, complete, repeatable example . " - Ella Svetlaya, null, ixSci, Abyx
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Very, you know, it’s problematic to understand what the problem is with you, if you didn’t show the file sending code. - Vladimir Martyanov
  • The problem is that there is no code, but Google did not help. I would like to give a ready-made solution - nikitas21
  • There is a service of questions, not a "make for me" service. - Vladimir Martyanov
  • I asked for an example of how to do it. - nikitas21

1 answer 1

Use WebClient :

 new WebClient().UploadFile(address, fileName); 

data2 data2 parameter in url, how ?data2=ssomething

  • one
    If I remember the features of PHP correctly, it will not work. data2 in its code is taken from $ _POST - only data from the request content gets into it. Parameters specified in url do not get there. Here the client is expected to multipart / form-data. Unfortunately, WebClient still has no methods for working with this type of query content. It is necessary either to alter the PHP script on the server, or use other classes to work with HTTP. - Sergey Rufanov