uni文件上传php,图片上传问题 uniapp+php

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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值