前端用ajax把base64格式的图片传过来,能成功保存,但是不知为何会多生成一个图片。
uploadImg () {
this.$http.post(this.$store.state.apiUrl + 'uploadImg', [
this.image
]).then(function (response) {
console.log(JSON.stringify(response.body));
}, function (response) {
console.log(JSON.stringify(response.body));
});
}
// php部分
define('UPLOAD_DIR', './uploads/');
$img = $this->request->post(0);
$start=strpos($img,',');
$img= substr($img,$start+1);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$fileName = UPLOAD_DIR . uniqid() . '.jpg';
$success = file_put_contents($fileName, $data);
$data=array();
if($success){
$data['status']=1;
$data['msg']= $img;
echo json_encode($data);
}else{
$data['status']=0;
$data['msg']='系统繁忙,请售后再试';
echo json_encode($data);
}
多生成了右边这个空白的图片
HUX布斯
慕后森
皈依舞