所以我正在尝试使用 C#、UWP 和后台上传器命名空间将文件上传到我的网络服务器。这是我的 C# 代码:
private async Task JamCloud_Upload_MP3()
{
try
{
Uri uri = new Uri("http://www.example.com/upload/upload.php");
var file = storagefile.file;
BackgroundUploader uploader = new BackgroundUploader();
uploader.SetRequestHeader("userfile", file.Name);
UploadOperation upload = uploader.CreateUpload(uri, file);
// Attach progress and completion handlers.
await upload.StartAsync();
//HandleUploadAsync(upload, true);
}
catch (Exception ex)
{
f.MessageBox("Upload Error: "+ ex);
}
}
因此,默认情况下,upload.method 是 POST。所以我不知道如何在服务器上捕捉这个 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);
}
?>
它似乎没有工作....任何人都可以帮助我吗?