Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7820173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:11:42+00:00 2026-06-02T07:11:42+00:00

Currently i have a c sharp application (Client app). and a web application written

  • 0

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:\test\a.jpg");

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

Here is the upload.php file to move the file..

$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");
 }

I’m not getting any errors from above code. but it does not seem to be working. Why is it? Am i missing something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:11:43+00:00Added an answer on June 2, 2026 at 7:11 am

    Your current PHP code is for handling multiple file uploads, but your 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");
    }
    ?>
    

    You also need to ensure that the ./files directory exists.

    I have tested the above PHP code with your C# code and it worked perfectly.

    • For more information on handling file uploads, refer to the PHP documentation.

    • For more information on uploading multiple files with C# and PHP, here are some helpful links:

      Upload files with HTTPWebrequest (multipart/form-data)

      Use Arrays in HTML Form Variables

      PHP: Uploading multiple files

      If you want something simple for uploading multiple files, you just just upload one file at a time to upload.php in a C# loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a Gridview , And I want to use client-side validation to
Currently I have an application that receives an uploaded file from my web application.
I have four classes which share some arrangement of four properties. I have currently
I currently have links w/ class=ajax that I want to retrieve the element with
I currently have a UINavigationController based application that works just fine. I'd like to
I want to design a new distributed application, but I have a few queries
I've written several Web MVC apps but never before in PHP, and I'm trying
Currently, I have an application, which will save a temporary screenshot, and let user
We have a huge ASP.NET web application which needs to be deployed to LIVE
I have a C sharp console application that captures a screenshot of a MS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.