微信小程序uploadFile使用需要注意的

1.客户端上传url要填腾讯云的uploadfile地址 
例子:https://xxxxx.qcloud.la/weapp/upload
wx.uploadFile
({
url: 'https://测试域名/weapp/upload',
filePath: tempFilePaths[ 0],
name: 'file',
formData:
{
'user': 'test'
},
success: function (res)
{
console.log(res.data)
var data = res.data
//do something
}
})

2.php接收

if ( $_FILES[ "file"][ "error"] > 0)
{
echo "Error: " . $_FILES[ "file"][ "error"] . "
"
;
}
else
{
echo "Upload: " . $_FILES[ "file"][ "name"] . "
"
;
echo "Type: " . $_FILES[ "file"][ "type"] . "
"
;
echo "Size: " . ( $_FILES[ "file"][ "size"] / 1024) . " Kb
"
;
echo "Stored in: " . $_FILES[ "file"][ "tmp_name"];
}


你可能感兴趣的:(微信小程序)