Hi,

I am using below code to upload a file from my C# to my PHP host.

I am able to get all the StringContent but not able to get the file.

When checking the ms.Length I can see the file has the correct size but when it goes to PHP I don’t know why it’s zero size.

In PHP I am using:

$file_name = '../mosques/' . $mousque_guid . '.png';


move_uploaded_file($_FILES['MosqueFile']['tmp_name'], $file_name);

Is there anything I am missing here?

and this is my code:

MultipartFormDataContent multipartContent = new MultipartFormDataContent();
multipartContent.Add(new StreamContent(ms), "MosqueFile", Guid.NewGuid().ToString() + ".png");
multipartContent.Add(new StringContent(EntryMouqueFirstName.Text), "first_name");
multipartContent.Add(new StringContent(EntryMouqueFamilyName.Text), "last_name");
multipartContent.Add(new StringContent(EntryMouqueEmailAddress.Text), "email");
multipartContent.Add(new StringContent(EntryMouqueName.Text), "mosque");
multipartContent.Add(new StringContent(CountryCode), "country");

var response = await client.PostAsync("https://my.domain.com/ws/submit_mouque.php", multipartContent);
var result = await response.Content.ReadAsStringAsync();

Thanks,
Jassim

    We'll need to see a bit more of your PHP to handle the upload. Like: where did $mosque_guid come from, what you did to determine the file's size, what value the move_uploaded_file() call returned...

      Write a Reply...