开发者

How can I send a file with the POST method from C# to a PHP file which (PHP) gets files from a HTML form by the '$_FILES' function?

First

I have a PHP file that gets data and file from a HTML form and uploads a file to a speci开发者_C百科fic 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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜