小程序wxml部分
wxml部分
<view class="weui-uploader__bd">
<view class="weui-uploader__files" id="uploaderFiles">
<block wx:for="{{files}}" wx:key="*this">
<view class="weui-uploader__file" bindtap="previewImage" id="{{item}}">
<image class="weui-uploader__img" src="{{item}}" mode="aspectFill" />
</view>
</block>
<view class="weui-uploader__file">
<image class="weui-uploader__img" src="http://www.dade.com:8080/static/img/369.png" mode="aspectFill" />
</view>
<view class="weui-uploader__file weui-uploader__file_status">
<image class="weui-uploader__img" src="http://www.dade.com:8080/static/img/369.png" mode="aspectFill" />
<view class="weui-uploader__file-content">
<view class="weui-loading"></view>
</view>
</view>
</view>
<view class="weui-uploader__input-box">
<view class="weui-uploader__input" bindtap="chooseImage"></view>
</view>
</view>
小程序js代码
小程序js部分
wx.chooseImage({
success (res) {
const tempFilePaths = res.tempFilePaths
wx.uploadFile({
url: 'http://www.dadesa.com:8080/index/imgswx', //仅为示例,非真实的接口地址
filePath: tempFilePaths[0],
name: 'file',
formData: {
'user': 'test'
},
success (res){
const data = res.data
console.log(res)
//do something
}
})
}
})
php?tp部分
/**
* 微信小程序上传图片
* */
public function imgswx(Request $request){
$file = $request->file('file');
$savename = \think\facade\Filesystem::disk('public')->putFile( 'img', $file);
$savename = "/storage/".$savename;
$savename = str_replace("\\",'/',$savename);
return json($savename);
}
|