微信小程序开发交流qq群 173683895
小程序源码:
wx.chooseImage({
success: function(res) {
var tempFilePaths = res.tempFilePaths
wx.uploadFile({
url: 'https://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址
filePath: tempFilePaths[0],
name: 'file',
formData:{
'openid': 'test'
},
success: function(res){
var data = res.data
//do something
}
})
}
})
php源码:
<?php
header("Content-Type:text/html;charset=utf8");
header("Access-Control-Allow-Origin: *"); //解决跨域
header('Access-Control-Allow-Methods:POST');// 响应类型
$link=mysql_connect("localhost","root","root");
mysql_select_db("rrapp_000", $link); //选择数据库
mysql_query("SET NAMES utf8");//解决中文乱码问题
header("Content-Type:text/html;charset=utf8");
if ($_FILES["file"]["error"] > 0)
{
echo "错误: " . $_FILES["file"]["error"] . "<br />";
}
else
{
$openid = $_POST['openid'];
$name=$_FILES['file']['name'];
$result = @mysql_query($strsql);
//循环读取数据并存入数组对象
$dlogs;$i=1;
while($row=mysql_fetch_array($rs))
{
$result = @mysql_query($strsql);
if($row["openid"]==$openid){
//修改数据库表ewei_shop_merch_user 中的字段
mysql_query("UPDATE ewei_shop_merch_user SET logo = '$name'
WHERE openid = '$openid'");
}
}
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "upload/" . $_FILES["file"]["name"];
}
?>