1

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.

4
  • What's the error message when uploading a file that is bigger than 2MB? Commented Jun 21, 2018 at 6:13
  • No error messages in C# and no log file in server also. When I click the upload button, bit time after the Application closes. Commented Jun 21, 2018 at 6:17
  • Try setting the Application.Exit(); after the try/catch block. Commented Jun 21, 2018 at 6:25
  • I put as you suggested but the program works some time as busy then closes. No error messages. Commented Jun 21, 2018 at 6:34

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. I only change the upload_max_filesize => from 2M to 16M. Now it works perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.