English 中文(简体)
从快速客户应用到PHP服务器
原标题:Upload to PHP server from c sharp client application

Currently i have a c sharp application (Client app). and a web application written php. I want to transfer some files whenever a particular action is performed at client side. Here is the client code to upload the file to php server..

private void button1_Click(object sender, EventArgs e)
{
    System.Net.WebClient Client = new System.Net.WebClient();

    Client.Headers.Add("Content-Type", "binary/octet-stream");

    byte[] result = Client.UploadFile("http://localhost/project1/upload.php", "POST",
                                      @"C:	esta.jpg");

    string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); 
}

这里是上载。 网址是:www.un.org。

$uploads_dir =  ./files/ ; //Directory to save the file that comes from client application.
foreach ($_FILES["pictures"]["error"] as $key => $error) {
  if ($error == UPLOAD_ERR_OK) {
     $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
     $name = $_FILES["pictures"]["name"][$key];
     move_uploaded_file($tmp_name, "$uploads_dir/$name");
 }

我不会从上述法典中发现任何错误。 但它似乎没有发挥作用。 为什么? 哪怕是失踪?

最佳回答

您目前的PHP代码是处理 多种文档上载,但您是 C# Code is only uploading one file.

You need to modify your PHP code somewhat, removing the foreach loop:

<?php
$uploads_dir =  ./files ; //Directory to save the file that comes from client application.
if ($_FILES["file"]["error"] == UPLOAD_ERR_OK) {
    $tmp_name = $_FILES["file"]["tmp_name"];
    $name = $_FILES["file"]["name"];
    move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
?>

您还需要确保有<代码>/files的名录。

我已经用你的C#代码测试了上述PHP代码,并做了完美的工作。

问题回答

您的《加拿大法典》似乎正确,但你试图利用全球“国际会计准则”的“假设”钥匙查阅文件。 看来,这在你的碎石法中并未具体指明。 我不知道如何这样做。 您可以设法了解如何在您的实验室中点名,具体做法是,在全球或利用阵列“钥匙”功能,对您进行打印。

Regards

Edit: I found this link that could help you to add a "name" to your uploaded file: http://www.bratched.com/en/home/dotnet/69-uploading-multiple-files-with-c.html





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签