(PHP+CI框架)下面,可以很方便的取到文件的信息,但是取不到formData中的信息。
比如下面的示例程序中,有formData:{'user': 'test'},在服务器端,可以用$_FILES[file]取到跟上传文件本身的数据。那么如何取得formData中传输的数据呢?
wx.chooseImage({
success: function(res) { var tempFilePaths = res.tempFilePaths
wx.uploadFile({
url: 'http://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址
filePath: tempFilePaths[0],
name: 'file',
})
}
})
查了一下,formdata是保存在$_POST中的,比如上面的情况,在服务器端:
_POST['user'];
比如下面的示例程序中,有formData:{'user': 'test'},在服务器端,可以用$_FILES[file]取到跟上传文件本身的数据。那么如何取得formData中传输的数据呢?
wx.chooseImage({
success: function(res) { var tempFilePaths = res.tempFilePaths
wx.uploadFile({
url: 'http://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址
filePath: tempFilePaths[0],
name: 'file',
formData:{
'user': 'test'
},success: function(res){
var data = res.data //do something
}})
}
})
查了一下,formdata是保存在$_POST中的,比如上面的情况,在服务器端:
_POST['user'];
可以得到$string的值是 'test'。
本文介绍在使用PHP与CodeIgniter框架时如何从wx.uploadFile接口中获取formData中的数据。通过$_POST['user']的方式可以成功读取到传输过来的'user'值。
343

被折叠的 条评论
为什么被折叠?



