duanmei1885 2018-06-21 05:48
浏览 92
已采纳

无法使用c#WebClient和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.

  • 写回答

1条回答 默认 最新

  • dongyong8071 2018-06-21 06:40
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。
  • ¥15 GitHubssh虚拟机连接不上