使用 php 在 cordova android 中读取文件上传参数

Reading parameters in file upload in cordova android using php

我正在尝试使用此插件 (https://github.com/apache/cordova-plugin-file-transfer/blob/master/doc/index.md) 实现文件 upload/download。但是我无法从 url.Here 读取参数(即文件名、mimetype)是 javascript 代码

//paramters for upload file
    var options = new FileUploadOptions();
             options.fileKey = "file";
             options.fileName = uri.substr(uri.lastIndexOf('/') + 1);
             options.mimeType = "text/plain";

上传url

var ft = new FileTransfer();
         ft.upload(uri, encodeURI('http://192.168.43.211/insiderapp/insiderapp_backend.php?action=uploadfile'), win, fail, options);

winfail是成功和错误的回调函数 实际问题是我无法在 php 文件中获得 options。 这是我的 php

function uploadFile(){
    //get the parameters
    $options=json_decode(file_get_contents('php://input'));
    echo $options->fileKey;
}

会returnsTrying to get property of non-object错误。

最后我发现 answer.Simply 读取 $_FILES 数组包含所有数据

if ($_FILES) {  
    print_r($_FILES);

    }else{
        echo 'error';
    }