uniapp上传图片及后台返回及时渲染
uniapp代码
<view>
<text style="margin-left: 40rpx;" class="all-tx color-base-text" @click="uploadskm">上传图</text>
<view>
<img @click="uploadskm" style="width:100rpx;margin-left: 40rpx;" src="http://youshuizeling.com/tian/img/tiange.png"/>
<img @click="" style="width:100rpx;margin-left: 150rpx;" :src= skmimgs />
</view>
</view>
先定义下
data() {
return {
skmimgs:'http://youshuizeling.com/tian/img/uploadskm.png'
};
},
在methods里面写方法
methods: {
// 新增代码上传收款码
uploadskm(){
uni.chooseImage({
success: (chooseImageRes) => {
const tempFilePaths = chooseImageRes.tempFilePaths;
uni.uploadFile({
url: 'https:www.baidu.com', //图片上传接口
filePath: tempFilePaths[0],
name: 'file',
formData: {
'user': 'test'
},
success: (uploadFileRes) => {
// skmimgs
var a = JSON.parse(uploadFileRes.data);
// console.log(a.data.pic_path);
// console.log('https://youshuizeling.com/'+ a.data.pic_path);
this.skmimgs ='https://youshuizeling.com/' + a.data.pic_path;
}
});
}
});
}
}
上传
this.$api.sendRequest({
url: '/api/memberwithdraw/apply',
data: {
apply_money: this.withdrawMoney,
transfer_type: this.bankAccountInfo.withdraw_type, //转账提现类型
realname: this.bankAccountInfo.realname,
mobile: this.bankAccountInfo.mobile,
bank_name: this.bankAccountInfo.branch_bank_name,
account_number: this.bankAccountInfo.bank_account,
applet_type: applet_type,
skmimg:this.skmimgs
},
success: res => {
if (res.code >= 0) {
this.$util.showToast({
title: '成功'
});
} else {
if (res.code >= 0) {
this.$util.showToast({
title: '失败'
});
}
},
fail: res => {
this.isSub = false;
}
});
php接受就可以操作
$_REQUEST
public function shangchuan(){
$base_path = $_SERVER['DOCUMENT_ROOT']."/uploads/h5img/"; // 接收文件目录
$target_path = $base_path .date("Ymds",time()).$_FILES['file']['name'];
if (move_uploaded_file($_FILES['file']['tmp_name'],$target_path)) {
$filearr = explode("wwwroot/",$target_path);
$filearr2 = explode("public/", $filearr[1]);
$fileinfo = $filearr2[0] .$filearr2[1] ;
$array = array (
"code" => "1",
"message" =>$fileinfo
);
echo json_encode($array);
} else {
$array = array (
"code" => "0",
"message" => "There was an error uploading the file, please try again!".$_FILES['file']['error']);
echo json_encode($array);
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?