S.Sakthybaalan
S.Sakthybaalan

Reputation: 519

Unable to upload file using c# WebClient and php FILES

The following C# code is used to upload the json file (~3.6 MB) to the server. Here, I am using WebClient to upload file to the server.

 private void btnUploadToServer_Click(object sender, EventArgs e)
        {
            try
            {
                using (WebClient client = new WebClient())
                {
                    string filePath = @"C:\Users\SAKTHY-PC\Desktop\app_erp_suneka.json";
                    var serverPath = new Uri(@"http://example.com/newSync/upload.php");
                    client.UploadFile(myUri,filePath);
                }

                   Application.Exit();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }

And I have a php script file (upload.php) in the following folder http://example.com/newSync/

<?php
    $filepath = $_FILES["file"]["tmp_name"];
    move_uploaded_file($filepath,"app_erp_suneka.json");
?>

The problem is unable to upload 2MB or more than 2MB file to the server. But less than 2MB file is successfully uploaded.

Upvotes: 1

Views: 1236

Answers (1)

Mikhail Kulygin
Mikhail Kulygin

Reputation: 76

You need to check and increase theese variables on your PHP server (php.ini file):

post_max_size => 8M
upload_max_filesize => 2M

Check it in phpinfo() or in server console:

php --info | grep upload_max_filesize
php --info | grep post_max_size
php --info | grep php.ini <-- shows where php.ini is

And control your php-log -- all errors and warnings are shown here:

php --info | grep error_log <-- where error_log is

Upvotes: 1

Related Questions