【发布时间】:2015-01-29 09:41:45
【问题描述】:
我正在尝试使用此插件(https://github.com/apache/cordova-plugin-file-transfer/blob/master/doc/index.md)实现文件上传/下载。但我无法从 url 读取参数(即文件名、mimetype)。这是 javascript 代码
//paramters for upload file
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = uri.substr(uri.lastIndexOf('/') + 1);
options.mimeType = "text/plain";
上传网址
var ft = new FileTransfer();
ft.upload(uri, encodeURI('http://192.168.43.211/insiderapp/insiderapp_backend.php?action=uploadfile'), win, fail, options);
win 和 fail 是成功和错误回调函数
实际问题是我无法在 php 文件中获取 options。
这是我的php
function uploadFile(){
//get the parameters
$options=json_decode(file_get_contents('php://input'));
echo $options->fileKey;
}
它将返回Trying to get property of non-object 错误。
【问题讨论】:
标签: javascript php android cordova