Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UWP C#BackgoundUploader不工作_C#_Php_Uwp_Background Transfer - Fatal编程技术网

UWP C#BackgoundUploader不工作

UWP C#BackgoundUploader不工作,c#,php,uwp,background-transfer,C#,Php,Uwp,Background Transfer,因此,我尝试使用C#、UWP和后台上传程序名称空间将文件上传到我的Web服务器。这是我的C#代码: 因此,默认情况下upload.method是POST。因此,我不知道如何在服务器上捕获此帖子,所以我编写了一个PHP文件,就像从html表单帖子捕获帖子一样 <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ $uploaddir = '/home/example/public_html/upload/'; $uploadfile = $upl

因此,我尝试使用C#、UWP和后台上传程序名称空间将文件上传到我的Web服务器。这是我的C#代码:

因此,默认情况下upload.method是POST。因此,我不知道如何在服务器上捕获此帖子,所以我编写了一个PHP文件,就像从html表单帖子捕获帖子一样

<?php

if($_SERVER['REQUEST_METHOD'] == 'POST'){

$uploaddir = '/home/example/public_html/upload/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
}

?>

它似乎不起作用。。。。有人能帮我吗?

找到了答案

  • 更改了upload.method=“PUT”//在C代码中,默认值是POST

  • 将PHP脚本更改为:

    <?php
    if($_SERVER['REQUEST_METHOD'] == 'PUT'){
        /* PUT data comes in on the stdin stream */
        $putdata = fopen("php://input", "r");
    
        /* Open a file for writing */
        $fp = fopen($_SERVER['HTTP_USERFILE'], "w");
    
        /* Read the data 1 KB at a time
           and write to the file */
        while ($data = fread($putdata, 1024))
          fwrite($fp, $data);
    
        /* Close the streams */
        fclose($fp);
        fclose($putdata);
    }   
    ?>
    
    
    

  • 在我看到这篇文章之前,我已经为此奋斗了很长时间。很好!谢谢!在这里,我们得到服务器在UploadOperation中返回的响应。有可能得到JSON响应吗?
    <?php
    if($_SERVER['REQUEST_METHOD'] == 'PUT'){
        /* PUT data comes in on the stdin stream */
        $putdata = fopen("php://input", "r");
    
        /* Open a file for writing */
        $fp = fopen($_SERVER['HTTP_USERFILE'], "w");
    
        /* Read the data 1 KB at a time
           and write to the file */
        while ($data = fread($putdata, 1024))
          fwrite($fp, $data);
    
        /* Close the streams */
        fclose($fp);
        fclose($putdata);
    }   
    ?>