chooseImage: async function() {
uni.chooseImage({
sourceType: sourceType[this.sourceTypeIndex],
// #ifdef MP-WEIXIN
sizeType: sizeType[this.sizeTypeIndex],
// #endif
count: this.imageLength - this.imageList.length,
success: (res) => {
console.log(res);
this.imageList = this.imageList.concat(res.tempFilePaths);
var file = [{
"name":"refund_pic",
"uri": res.tempFilePaths[0]
}]
uni.uploadFile({
url: this.apiServer + '/Memberrefund/upload_pic', //仅为示例,非真实的接口地址
filePath: res.tempFilePaths[0],
// files:file,
name: 'refund_pic1',
fileType:'image',
header: {
'content-type': 'multipart/form-data' //自定义请求头信息
},
formData: {
'user': 'test'
},
success: (uploadFileRes) => {
console.log('chenggong');
console.log(uploadFileRes.data);
},
fail:(shibai)=>{
console.log('shibai');
}
});
}
})
-------------------------------------------------------PHP--------------------------------------------------------
public function upload_pic() {
var_dump(request()->file('refund_pic1'));die;
$refund_pic = array();
$refund_pic[1] = 'refund_pic1';
$refund_pic[2] = 'refund_pic2';
$refund_pic[3] = 'refund_pic3';
$pic_array = array();
$dir = BASE_UPLOAD_PATH.DS.ATTACH_PATH . DS . 'refund' . DS;
$count = 1;
foreach ($refund_pic as $pic) {
if (!empty($_FILES[$pic]['name'])) {
$upload=request()->file($pic);
$result = $upload->rule('uniqid')->validate(['ext' => ALLOW_IMG_EXT])->move($dir);
if ($result) {
$pic_array[$count] = $result->getFilename();
} else {
$pic_array[$count] = '';
}
}
$count++;
}
return $pic_array;
}